Multi-level marketing “legs” investment rule
Multi-level marketing related challenge.
A peer wants to get rewarded. So it attracted N
investors (N>=1
), each i-th investor invested x[i]
. When a total sum exceeds threshold x[0]+x[1]+...+x[N-1] >= T
a peer could be rewarded. But only if a following conditions are satisfied:
- Minimum amount of investors should be greater than
M
, (M<=N
) - For at least one integer
k
, wherek>=M
andk<=N
, anyk
investors have to invest at leastT/k
each;
Given N, x, T, M
you should determine whether the peer's reward is generated or not (boolean result, "yes" or "no"). Shortest code wins.
Examples:
N=5; M=3; T=10000
, in order to generate the peer's reward one of the following must be satisfied:
- any 3 invested at least 3334 each
- any 4 invested at least 2500 each
- all 5 invested at least 2000 each
N=6; M=2; T=5000
:
- any 2 invested at least 2500 each
- any 3 invested at least 1667 each
- any 4 invested at least 1250 each
- any 5 invested at least 1000 each
- all 6 invested at least 834 each
generalized: for any k
, where k>=M
and k<=N
:
- any
k
ofN
investors invested at leastT/k
each
Test cases:
format:
N, x, T, M -> correct answer
6, [999, 999, 59, 0, 0, 0], 180, 3 -> 0
6, [0, 60, 0, 60, 60, 0], 180, 3 -> 1
6, [179, 89, 59, 44, 35, 29], 180, 3 -> 0
6, [179, 89, 59, 44, 35, 30], 180, 3 -> 1
6, [179, 89, 59, 44, 36, 29], 180, 3 -> 1
6, [179, 90, 59, 44, 35, 29], 180, 3 -> 0
6, [30, 30, 30, 30, 29, 30], 180, 3 -> 0
6, [30, 30, 30, 30, 30, 30], 180, 3 -> 1
code-golf decision-problem
|
show 9 more comments
Multi-level marketing related challenge.
A peer wants to get rewarded. So it attracted N
investors (N>=1
), each i-th investor invested x[i]
. When a total sum exceeds threshold x[0]+x[1]+...+x[N-1] >= T
a peer could be rewarded. But only if a following conditions are satisfied:
- Minimum amount of investors should be greater than
M
, (M<=N
) - For at least one integer
k
, wherek>=M
andk<=N
, anyk
investors have to invest at leastT/k
each;
Given N, x, T, M
you should determine whether the peer's reward is generated or not (boolean result, "yes" or "no"). Shortest code wins.
Examples:
N=5; M=3; T=10000
, in order to generate the peer's reward one of the following must be satisfied:
- any 3 invested at least 3334 each
- any 4 invested at least 2500 each
- all 5 invested at least 2000 each
N=6; M=2; T=5000
:
- any 2 invested at least 2500 each
- any 3 invested at least 1667 each
- any 4 invested at least 1250 each
- any 5 invested at least 1000 each
- all 6 invested at least 834 each
generalized: for any k
, where k>=M
and k<=N
:
- any
k
ofN
investors invested at leastT/k
each
Test cases:
format:
N, x, T, M -> correct answer
6, [999, 999, 59, 0, 0, 0], 180, 3 -> 0
6, [0, 60, 0, 60, 60, 0], 180, 3 -> 1
6, [179, 89, 59, 44, 35, 29], 180, 3 -> 0
6, [179, 89, 59, 44, 35, 30], 180, 3 -> 1
6, [179, 89, 59, 44, 36, 29], 180, 3 -> 1
6, [179, 90, 59, 44, 35, 29], 180, 3 -> 0
6, [30, 30, 30, 30, 29, 30], 180, 3 -> 0
6, [30, 30, 30, 30, 30, 30], 180, 3 -> 1
code-golf decision-problem
N
is implied bylen(x)
, I suppose we can but do not have to take it as an input, right?
– Jonathan Allan
yesterday
1
@JonathanAllan Sure, if your language allows it, and writinglen(x)
will be shorter than writingN
. That is made, because for dynamically allocated arrayx
in C there is no directlen(x)
function - so you may always refer to length asN
. For convenience, you may consider all input dataN, x, T, M
as some externally defined constants, or some language built-ins.
– xakepp35
yesterday
1
I don't think those notifications reached them (with the hyphens) as I got them in my inbox.
– Jonathan Allan
yesterday
1
@JonathanAllan not quite familar with pinging syntax, and non-latin names.. maybe they will return some day :)
– xakepp35
yesterday
1
Also, can output be reversed? A falsey value fortrue
and truthy value forfalse
?
– Shaggy
yesterday
|
show 9 more comments
Multi-level marketing related challenge.
A peer wants to get rewarded. So it attracted N
investors (N>=1
), each i-th investor invested x[i]
. When a total sum exceeds threshold x[0]+x[1]+...+x[N-1] >= T
a peer could be rewarded. But only if a following conditions are satisfied:
- Minimum amount of investors should be greater than
M
, (M<=N
) - For at least one integer
k
, wherek>=M
andk<=N
, anyk
investors have to invest at leastT/k
each;
Given N, x, T, M
you should determine whether the peer's reward is generated or not (boolean result, "yes" or "no"). Shortest code wins.
Examples:
N=5; M=3; T=10000
, in order to generate the peer's reward one of the following must be satisfied:
- any 3 invested at least 3334 each
- any 4 invested at least 2500 each
- all 5 invested at least 2000 each
N=6; M=2; T=5000
:
- any 2 invested at least 2500 each
- any 3 invested at least 1667 each
- any 4 invested at least 1250 each
- any 5 invested at least 1000 each
- all 6 invested at least 834 each
generalized: for any k
, where k>=M
and k<=N
:
- any
k
ofN
investors invested at leastT/k
each
Test cases:
format:
N, x, T, M -> correct answer
6, [999, 999, 59, 0, 0, 0], 180, 3 -> 0
6, [0, 60, 0, 60, 60, 0], 180, 3 -> 1
6, [179, 89, 59, 44, 35, 29], 180, 3 -> 0
6, [179, 89, 59, 44, 35, 30], 180, 3 -> 1
6, [179, 89, 59, 44, 36, 29], 180, 3 -> 1
6, [179, 90, 59, 44, 35, 29], 180, 3 -> 0
6, [30, 30, 30, 30, 29, 30], 180, 3 -> 0
6, [30, 30, 30, 30, 30, 30], 180, 3 -> 1
code-golf decision-problem
Multi-level marketing related challenge.
A peer wants to get rewarded. So it attracted N
investors (N>=1
), each i-th investor invested x[i]
. When a total sum exceeds threshold x[0]+x[1]+...+x[N-1] >= T
a peer could be rewarded. But only if a following conditions are satisfied:
- Minimum amount of investors should be greater than
M
, (M<=N
) - For at least one integer
k
, wherek>=M
andk<=N
, anyk
investors have to invest at leastT/k
each;
Given N, x, T, M
you should determine whether the peer's reward is generated or not (boolean result, "yes" or "no"). Shortest code wins.
Examples:
N=5; M=3; T=10000
, in order to generate the peer's reward one of the following must be satisfied:
- any 3 invested at least 3334 each
- any 4 invested at least 2500 each
- all 5 invested at least 2000 each
N=6; M=2; T=5000
:
- any 2 invested at least 2500 each
- any 3 invested at least 1667 each
- any 4 invested at least 1250 each
- any 5 invested at least 1000 each
- all 6 invested at least 834 each
generalized: for any k
, where k>=M
and k<=N
:
- any
k
ofN
investors invested at leastT/k
each
Test cases:
format:
N, x, T, M -> correct answer
6, [999, 999, 59, 0, 0, 0], 180, 3 -> 0
6, [0, 60, 0, 60, 60, 0], 180, 3 -> 1
6, [179, 89, 59, 44, 35, 29], 180, 3 -> 0
6, [179, 89, 59, 44, 35, 30], 180, 3 -> 1
6, [179, 89, 59, 44, 36, 29], 180, 3 -> 1
6, [179, 90, 59, 44, 35, 29], 180, 3 -> 0
6, [30, 30, 30, 30, 29, 30], 180, 3 -> 0
6, [30, 30, 30, 30, 30, 30], 180, 3 -> 1
code-golf decision-problem
code-golf decision-problem
edited 19 hours ago
Glorfindel
147119
147119
asked yesterday
xakepp35xakepp35
1728
1728
N
is implied bylen(x)
, I suppose we can but do not have to take it as an input, right?
– Jonathan Allan
yesterday
1
@JonathanAllan Sure, if your language allows it, and writinglen(x)
will be shorter than writingN
. That is made, because for dynamically allocated arrayx
in C there is no directlen(x)
function - so you may always refer to length asN
. For convenience, you may consider all input dataN, x, T, M
as some externally defined constants, or some language built-ins.
– xakepp35
yesterday
1
I don't think those notifications reached them (with the hyphens) as I got them in my inbox.
– Jonathan Allan
yesterday
1
@JonathanAllan not quite familar with pinging syntax, and non-latin names.. maybe they will return some day :)
– xakepp35
yesterday
1
Also, can output be reversed? A falsey value fortrue
and truthy value forfalse
?
– Shaggy
yesterday
|
show 9 more comments
N
is implied bylen(x)
, I suppose we can but do not have to take it as an input, right?
– Jonathan Allan
yesterday
1
@JonathanAllan Sure, if your language allows it, and writinglen(x)
will be shorter than writingN
. That is made, because for dynamically allocated arrayx
in C there is no directlen(x)
function - so you may always refer to length asN
. For convenience, you may consider all input dataN, x, T, M
as some externally defined constants, or some language built-ins.
– xakepp35
yesterday
1
I don't think those notifications reached them (with the hyphens) as I got them in my inbox.
– Jonathan Allan
yesterday
1
@JonathanAllan not quite familar with pinging syntax, and non-latin names.. maybe they will return some day :)
– xakepp35
yesterday
1
Also, can output be reversed? A falsey value fortrue
and truthy value forfalse
?
– Shaggy
yesterday
N
is implied by len(x)
, I suppose we can but do not have to take it as an input, right?– Jonathan Allan
yesterday
N
is implied by len(x)
, I suppose we can but do not have to take it as an input, right?– Jonathan Allan
yesterday
1
1
@JonathanAllan Sure, if your language allows it, and writing
len(x)
will be shorter than writing N
. That is made, because for dynamically allocated array x
in C there is no direct len(x)
function - so you may always refer to length as N
. For convenience, you may consider all input data N, x, T, M
as some externally defined constants, or some language built-ins.– xakepp35
yesterday
@JonathanAllan Sure, if your language allows it, and writing
len(x)
will be shorter than writing N
. That is made, because for dynamically allocated array x
in C there is no direct len(x)
function - so you may always refer to length as N
. For convenience, you may consider all input data N, x, T, M
as some externally defined constants, or some language built-ins.– xakepp35
yesterday
1
1
I don't think those notifications reached them (with the hyphens) as I got them in my inbox.
– Jonathan Allan
yesterday
I don't think those notifications reached them (with the hyphens) as I got them in my inbox.
– Jonathan Allan
yesterday
1
1
@JonathanAllan not quite familar with pinging syntax, and non-latin names.. maybe they will return some day :)
– xakepp35
yesterday
@JonathanAllan not quite familar with pinging syntax, and non-latin names.. maybe they will return some day :)
– xakepp35
yesterday
1
1
Also, can output be reversed? A falsey value for
true
and truthy value for false
?– Shaggy
yesterday
Also, can output be reversed? A falsey value for
true
and truthy value for false
?– Shaggy
yesterday
|
show 9 more comments
13 Answers
13
active
oldest
votes
Jelly, 12 9 bytes
ṢṚ×J$ṫ⁵<Ṃ
A full program which accepts x T M
and prints 0
if the peer is rewarded and 1
if not.
Try it online!
How?
ṢṚ×J$ṫ⁵<Ṃ - Main Link: list of numbers, x; number, T e.g. [100, 50, 77, 22, 14, 45], 180
Ṣ - sort x [ 14, 22, 45, 50, 77,100]
Ṛ - reverse [100, 77, 50, 45, 22, 14]
$ - last two links as a monad:
J - range of length [ 1, 2, 3, 4, 5, 6]
× - multiply [100,154,150,180,110, 84]
ṫ - tail from index:
⁵ - 5th argument (3rd input), M (e.g. M=3) [ 150,180,110, 84]
< - less than T? [ 1, 0, 1, 1]
Ṃ - minimum 0
seems not working: tio.run/##y0rNyan8///hzkWHp/uoHJ5wbMnDnasfNW61ebiz6dCah7sW/P//…
– xakepp35
yesterday
in example third investor invested less than 1/3rd of T (less than 33), but result still counted as positive ("any k invested at least T/k each" failed)
– xakepp35
yesterday
Yeah, I created it using prefixes of reverse-sorted values and thought I could change it to postfixes of sorted, but actually couldn't because I'm then tailing... reverted :)
– Jonathan Allan
yesterday
1
Yeah, now I've finished golfing I'm writing an explanation.
– Jonathan Allan
yesterday
1
It now "prints0
if the peer is rewarded and1
if not". (i.e.0
is "yes"). It saves 1 byte :)
– Jonathan Allan
yesterday
|
show 4 more comments
05AB1E, 9 bytes
{Rƶ.ssè›ß
Try it online or verify all test cases.
Port of @JonathanAllan's Jelly answer, so also takes the inputs x T M
and outputs 0
for "yes"
and 1
for "no"
. If this is not allowed, and it should be inverted, a trailing _
can be added.
Explanation:
{ # Sort the (implicit) input `x`
# i.e. `x`=[100,50,77,22,14,45] → [14,22,45,50,77,100]
R # Reverse it
# i.e. [14,22,45,50,77,100] → [100,77,50,45,22,14]
ƶ # Multiply it by it's 1-indexed range
# i.e. [100,77,50,45,22,14] → [100,154,150,180,110,84]
.s # Get all the suffices of this list
# i.e. [100,154,150,180,110,84]
# → [[84],[110,84],[180,110,84],[150,180,110,84],[100,154,150,180,110,84]]
s # Swap to take the (implicit) input `T`
è # Get the prefix at index `T`
# i.e. [[84],[110,84],[180,110,84],[150,180,110,84],[100,154,150,180,110,84]]
# and `T=3` → [150,180,110,84]
› # Check for each list-value if the (implicit) input `M` is larger than it
# i.e. [150,180,110,84] and `M`=180 → [1,0,1,1]
ß # And pop and push the minimum value in the list (which is output implicitly)
# i.e. [1,0,1,1] → 0
Alternative for .ssè
:
sG¦}
Try it online or verify all test cases.
Explanation:
s # Swap to take the (implicit) input `T`
G } # Loop `T-1` times:
¦ # Remove the first item from the list that many times
# i.e. [100,154,150,180,110,84] and `T=3` → [150,180,110,84]
1
I didn't stated on "how should you map output", just that it have to be boolean (to has only 2 states). So yes, definetely you may use 0 for "yes" and 1 for "no" :)
– xakepp35
20 hours ago
add a comment |
C# (Visual C# Interactive Compiler), 83 bytes
(n,x,t,m)=>n>=m&&new int[n-m+1].Where((_,b)=>x.Count(a=>a>=t/(b+m))>=b+m).Count()>0
Short-circuiting AND (&&
) is needed, or else if m > n
, the array will be initialized with a negative number. Uses a different algorithm than the other existing submissions.
// Takes in 4 parameters as input
(n,x,t,m)=>
// Is n greater than or equal to m?
n>=m
// If it isn't, stop right there and return false. If it is, continue
&&
// Create a new array with the length of all the numbers from m to n, inclusive
new int[n-m+1]
// And filter the results by
.Where((_,b)=>
// If the number of people that invested more than the total amount divided by the index plus m
x.Count(a=>a>=t/(b+m))
// Is greater than the index plus m
>= b+m)
// And check if there is at least one value in the filtered IEnumerable<int>, and if there is, return true
.Count()>0
Try it online!
66? - Although once again cursed by Enumerable.Range :)
– dana
22 hours ago
I thought of that, and stated in the description that N>=1, and M<=N So you may shorten your solution a bit :)
– xakepp35
20 hours ago
add a comment |
JavaScript, 54 52 bytes
(x,t,m,n)=>x.sort((a,b)=>a-b).some(i=>i*n-->=t&n>=m)
Try it online
Also 35-40% more performant that 72-byted solution. Lovely code, felt like its ready to be embedded in production MLM-related web projects :^)
– xakepp35
20 hours ago
add a comment |
Retina, 79 bytes
d+
*
O^`_+(?=.*])
_+(?=.*])(?<=(W+_+)+)
$#1*$&
+`W+_+(.*_)_$
$1
(_+).*], 1,
Try it online! Takes input in the format [x], T, M
. Link includes test cases. Explanation:
d+
*
Convert to unary.
O^`_+(?=.*])
Sort [x]
in descending order.
_+(?=.*])(?<=(W+_+)+)
$#1*$&
Multiply each element of [x]
by its index.
+`W+_+(.*_)_$
$1
Delete the first M-1
elements of [x]
.
(_+).*], 1,
Test whether any remaining element of [x]
is greater or equal to T
.
add a comment |
Perl 6, 46 33 29 bytes
{$^b>all $^a.sort Z*[...] @_}
Try it online!
Anonymous code blocks that takes input in the form list, amount, length of list, minimum amount of investors
and returns a truthy/falsey all
Junction, where truthy is failed and falsey is success.
Explanation:
{ } # Anonymous code block
all # Are all of
$^a.sort # The sorted list
Z* # Zip multiplied by
[...] @_ # The range from length of list to the minimum amount
$^b> # Not smaller than the given amount?
add a comment |
05AB1E, 6 bytes
Input taken in the order T
, N
, x
, M
Output is 0
for peer reward and 1
if not
Ÿs{*›W
Try it online!
or as a Test Suite
Explanation
Ÿ # push the range [N ... T]
s{ # push the list x sorted ascending
* # elementwise multiplication (crops to shortest list)
› # for each element, check if M is greater than it
W # push min of the result
# output implicitly
Nice trick of using*
with the range to implicitly crop the list!
– Kevin Cruijssen
15 hours ago
add a comment |
JavaScript, 72 bytes
Code
(x,T,M)=>x.sort(t=(d,e)=>e-d).map((s,i)=>s*i+s).slice(M-1).sort(t)[0]>=T
Try it online!
Accepts input in format (x,T,M)
Explanation
x.sort(t=(d,e)=>e-d) \sort numbers in reverse numerical order
.map((s,i)=>s*i+s) \Multiply each number in array by position(1 indexed) in array
.slice(M-1) \Remove the first M-1 elements (at least M people)
.sort(t)[0] \Get the maximum value in the array
>=T \True if the maximum value is >= the threshold
54 bytes?
– Arnauld
yesterday
(Or 53 bytes if the meaning of the Boolean value can be inverted.)
– Arnauld
yesterday
@Arnauld, 52 bytes ;)
– Shaggy
yesterday
(By the way, I came up with my solution independently of your comment, in case you were wondering - it's a port of my Japt solution. On mobile so can't see timestamps properly to tell who posted first.)
– Shaggy
yesterday
add a comment |
Python 3, 136 bytes
Just tests the conditions to make sure they are met. 1 if the reward is given, 0 if not.
lambda N,x,T,M:(sum(x)>=T)*(M<=N)*any(any(all(j>=T/k for j in i)for i in combinations(x,k))for k in range(M,N+1))
from itertools import*
Try it online!
add a comment |
Python, 71 65 bytes
lambda x,T,M:all(i*v<T for i,v in enumerate(sorted(x)[-M::-1],M))
Try it online!
An unnamed function; port of my Jelly answer. As such "yes" is False
and "no" is True
. Here, however, we discard test-cases as a part of the reversal and take advantage of the ability to initiate the enumerate
count to M
. (min
would also work in place of all
)
add a comment |
R, 43 42 bytes
-1 bytes by implementing the approach even more closely
function(N,x,S,M)min(sort(x,T)[M:N]*M:N<S)
Try it online!
Simple R implementation of Jonathan's Jelly approach. I tried a bunch of variations but this pips the best I could think of by a few bytes.
1 implies failure, 0 implies success.
add a comment |
C# (.NET Core), 129 bytes
Without LINQ.
(n,q,t,m)=>{int c=0;for(var k=m;k<=q.Length;){for(var j=0;j<q.Length;){if(q[j++]>=t/k)c++;}c=c>=k++?1:0;if(c>0)break;}return c;};
Try it online!
add a comment |
Japt, 16 14 13 11 bytes
ñ í*WõX)d¨V
Try it
ñ í*WõX)d¨V
:Implicit input of array U=x and integers V=T, W=M & X=N
ñ :Sort U
í :Interleave with
WõX : Range [W,X]
* : And reduce each pair of elements by multiplication
) :End interleaving
d :Any
¨V : Greater than or equal to V
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "200"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178443%2fmulti-level-marketing-legs-investment-rule%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
13 Answers
13
active
oldest
votes
13 Answers
13
active
oldest
votes
active
oldest
votes
active
oldest
votes
Jelly, 12 9 bytes
ṢṚ×J$ṫ⁵<Ṃ
A full program which accepts x T M
and prints 0
if the peer is rewarded and 1
if not.
Try it online!
How?
ṢṚ×J$ṫ⁵<Ṃ - Main Link: list of numbers, x; number, T e.g. [100, 50, 77, 22, 14, 45], 180
Ṣ - sort x [ 14, 22, 45, 50, 77,100]
Ṛ - reverse [100, 77, 50, 45, 22, 14]
$ - last two links as a monad:
J - range of length [ 1, 2, 3, 4, 5, 6]
× - multiply [100,154,150,180,110, 84]
ṫ - tail from index:
⁵ - 5th argument (3rd input), M (e.g. M=3) [ 150,180,110, 84]
< - less than T? [ 1, 0, 1, 1]
Ṃ - minimum 0
seems not working: tio.run/##y0rNyan8///hzkWHp/uoHJ5wbMnDnasfNW61ebiz6dCah7sW/P//…
– xakepp35
yesterday
in example third investor invested less than 1/3rd of T (less than 33), but result still counted as positive ("any k invested at least T/k each" failed)
– xakepp35
yesterday
Yeah, I created it using prefixes of reverse-sorted values and thought I could change it to postfixes of sorted, but actually couldn't because I'm then tailing... reverted :)
– Jonathan Allan
yesterday
1
Yeah, now I've finished golfing I'm writing an explanation.
– Jonathan Allan
yesterday
1
It now "prints0
if the peer is rewarded and1
if not". (i.e.0
is "yes"). It saves 1 byte :)
– Jonathan Allan
yesterday
|
show 4 more comments
Jelly, 12 9 bytes
ṢṚ×J$ṫ⁵<Ṃ
A full program which accepts x T M
and prints 0
if the peer is rewarded and 1
if not.
Try it online!
How?
ṢṚ×J$ṫ⁵<Ṃ - Main Link: list of numbers, x; number, T e.g. [100, 50, 77, 22, 14, 45], 180
Ṣ - sort x [ 14, 22, 45, 50, 77,100]
Ṛ - reverse [100, 77, 50, 45, 22, 14]
$ - last two links as a monad:
J - range of length [ 1, 2, 3, 4, 5, 6]
× - multiply [100,154,150,180,110, 84]
ṫ - tail from index:
⁵ - 5th argument (3rd input), M (e.g. M=3) [ 150,180,110, 84]
< - less than T? [ 1, 0, 1, 1]
Ṃ - minimum 0
seems not working: tio.run/##y0rNyan8///hzkWHp/uoHJ5wbMnDnasfNW61ebiz6dCah7sW/P//…
– xakepp35
yesterday
in example third investor invested less than 1/3rd of T (less than 33), but result still counted as positive ("any k invested at least T/k each" failed)
– xakepp35
yesterday
Yeah, I created it using prefixes of reverse-sorted values and thought I could change it to postfixes of sorted, but actually couldn't because I'm then tailing... reverted :)
– Jonathan Allan
yesterday
1
Yeah, now I've finished golfing I'm writing an explanation.
– Jonathan Allan
yesterday
1
It now "prints0
if the peer is rewarded and1
if not". (i.e.0
is "yes"). It saves 1 byte :)
– Jonathan Allan
yesterday
|
show 4 more comments
Jelly, 12 9 bytes
ṢṚ×J$ṫ⁵<Ṃ
A full program which accepts x T M
and prints 0
if the peer is rewarded and 1
if not.
Try it online!
How?
ṢṚ×J$ṫ⁵<Ṃ - Main Link: list of numbers, x; number, T e.g. [100, 50, 77, 22, 14, 45], 180
Ṣ - sort x [ 14, 22, 45, 50, 77,100]
Ṛ - reverse [100, 77, 50, 45, 22, 14]
$ - last two links as a monad:
J - range of length [ 1, 2, 3, 4, 5, 6]
× - multiply [100,154,150,180,110, 84]
ṫ - tail from index:
⁵ - 5th argument (3rd input), M (e.g. M=3) [ 150,180,110, 84]
< - less than T? [ 1, 0, 1, 1]
Ṃ - minimum 0
Jelly, 12 9 bytes
ṢṚ×J$ṫ⁵<Ṃ
A full program which accepts x T M
and prints 0
if the peer is rewarded and 1
if not.
Try it online!
How?
ṢṚ×J$ṫ⁵<Ṃ - Main Link: list of numbers, x; number, T e.g. [100, 50, 77, 22, 14, 45], 180
Ṣ - sort x [ 14, 22, 45, 50, 77,100]
Ṛ - reverse [100, 77, 50, 45, 22, 14]
$ - last two links as a monad:
J - range of length [ 1, 2, 3, 4, 5, 6]
× - multiply [100,154,150,180,110, 84]
ṫ - tail from index:
⁵ - 5th argument (3rd input), M (e.g. M=3) [ 150,180,110, 84]
< - less than T? [ 1, 0, 1, 1]
Ṃ - minimum 0
edited yesterday
answered yesterday
Jonathan AllanJonathan Allan
51k534166
51k534166
seems not working: tio.run/##y0rNyan8///hzkWHp/uoHJ5wbMnDnasfNW61ebiz6dCah7sW/P//…
– xakepp35
yesterday
in example third investor invested less than 1/3rd of T (less than 33), but result still counted as positive ("any k invested at least T/k each" failed)
– xakepp35
yesterday
Yeah, I created it using prefixes of reverse-sorted values and thought I could change it to postfixes of sorted, but actually couldn't because I'm then tailing... reverted :)
– Jonathan Allan
yesterday
1
Yeah, now I've finished golfing I'm writing an explanation.
– Jonathan Allan
yesterday
1
It now "prints0
if the peer is rewarded and1
if not". (i.e.0
is "yes"). It saves 1 byte :)
– Jonathan Allan
yesterday
|
show 4 more comments
seems not working: tio.run/##y0rNyan8///hzkWHp/uoHJ5wbMnDnasfNW61ebiz6dCah7sW/P//…
– xakepp35
yesterday
in example third investor invested less than 1/3rd of T (less than 33), but result still counted as positive ("any k invested at least T/k each" failed)
– xakepp35
yesterday
Yeah, I created it using prefixes of reverse-sorted values and thought I could change it to postfixes of sorted, but actually couldn't because I'm then tailing... reverted :)
– Jonathan Allan
yesterday
1
Yeah, now I've finished golfing I'm writing an explanation.
– Jonathan Allan
yesterday
1
It now "prints0
if the peer is rewarded and1
if not". (i.e.0
is "yes"). It saves 1 byte :)
– Jonathan Allan
yesterday
seems not working: tio.run/##y0rNyan8///hzkWHp/uoHJ5wbMnDnasfNW61ebiz6dCah7sW/P//…
– xakepp35
yesterday
seems not working: tio.run/##y0rNyan8///hzkWHp/uoHJ5wbMnDnasfNW61ebiz6dCah7sW/P//…
– xakepp35
yesterday
in example third investor invested less than 1/3rd of T (less than 33), but result still counted as positive ("any k invested at least T/k each" failed)
– xakepp35
yesterday
in example third investor invested less than 1/3rd of T (less than 33), but result still counted as positive ("any k invested at least T/k each" failed)
– xakepp35
yesterday
Yeah, I created it using prefixes of reverse-sorted values and thought I could change it to postfixes of sorted, but actually couldn't because I'm then tailing... reverted :)
– Jonathan Allan
yesterday
Yeah, I created it using prefixes of reverse-sorted values and thought I could change it to postfixes of sorted, but actually couldn't because I'm then tailing... reverted :)
– Jonathan Allan
yesterday
1
1
Yeah, now I've finished golfing I'm writing an explanation.
– Jonathan Allan
yesterday
Yeah, now I've finished golfing I'm writing an explanation.
– Jonathan Allan
yesterday
1
1
It now "prints
0
if the peer is rewarded and 1
if not". (i.e. 0
is "yes"). It saves 1 byte :)– Jonathan Allan
yesterday
It now "prints
0
if the peer is rewarded and 1
if not". (i.e. 0
is "yes"). It saves 1 byte :)– Jonathan Allan
yesterday
|
show 4 more comments
05AB1E, 9 bytes
{Rƶ.ssè›ß
Try it online or verify all test cases.
Port of @JonathanAllan's Jelly answer, so also takes the inputs x T M
and outputs 0
for "yes"
and 1
for "no"
. If this is not allowed, and it should be inverted, a trailing _
can be added.
Explanation:
{ # Sort the (implicit) input `x`
# i.e. `x`=[100,50,77,22,14,45] → [14,22,45,50,77,100]
R # Reverse it
# i.e. [14,22,45,50,77,100] → [100,77,50,45,22,14]
ƶ # Multiply it by it's 1-indexed range
# i.e. [100,77,50,45,22,14] → [100,154,150,180,110,84]
.s # Get all the suffices of this list
# i.e. [100,154,150,180,110,84]
# → [[84],[110,84],[180,110,84],[150,180,110,84],[100,154,150,180,110,84]]
s # Swap to take the (implicit) input `T`
è # Get the prefix at index `T`
# i.e. [[84],[110,84],[180,110,84],[150,180,110,84],[100,154,150,180,110,84]]
# and `T=3` → [150,180,110,84]
› # Check for each list-value if the (implicit) input `M` is larger than it
# i.e. [150,180,110,84] and `M`=180 → [1,0,1,1]
ß # And pop and push the minimum value in the list (which is output implicitly)
# i.e. [1,0,1,1] → 0
Alternative for .ssè
:
sG¦}
Try it online or verify all test cases.
Explanation:
s # Swap to take the (implicit) input `T`
G } # Loop `T-1` times:
¦ # Remove the first item from the list that many times
# i.e. [100,154,150,180,110,84] and `T=3` → [150,180,110,84]
1
I didn't stated on "how should you map output", just that it have to be boolean (to has only 2 states). So yes, definetely you may use 0 for "yes" and 1 for "no" :)
– xakepp35
20 hours ago
add a comment |
05AB1E, 9 bytes
{Rƶ.ssè›ß
Try it online or verify all test cases.
Port of @JonathanAllan's Jelly answer, so also takes the inputs x T M
and outputs 0
for "yes"
and 1
for "no"
. If this is not allowed, and it should be inverted, a trailing _
can be added.
Explanation:
{ # Sort the (implicit) input `x`
# i.e. `x`=[100,50,77,22,14,45] → [14,22,45,50,77,100]
R # Reverse it
# i.e. [14,22,45,50,77,100] → [100,77,50,45,22,14]
ƶ # Multiply it by it's 1-indexed range
# i.e. [100,77,50,45,22,14] → [100,154,150,180,110,84]
.s # Get all the suffices of this list
# i.e. [100,154,150,180,110,84]
# → [[84],[110,84],[180,110,84],[150,180,110,84],[100,154,150,180,110,84]]
s # Swap to take the (implicit) input `T`
è # Get the prefix at index `T`
# i.e. [[84],[110,84],[180,110,84],[150,180,110,84],[100,154,150,180,110,84]]
# and `T=3` → [150,180,110,84]
› # Check for each list-value if the (implicit) input `M` is larger than it
# i.e. [150,180,110,84] and `M`=180 → [1,0,1,1]
ß # And pop and push the minimum value in the list (which is output implicitly)
# i.e. [1,0,1,1] → 0
Alternative for .ssè
:
sG¦}
Try it online or verify all test cases.
Explanation:
s # Swap to take the (implicit) input `T`
G } # Loop `T-1` times:
¦ # Remove the first item from the list that many times
# i.e. [100,154,150,180,110,84] and `T=3` → [150,180,110,84]
1
I didn't stated on "how should you map output", just that it have to be boolean (to has only 2 states). So yes, definetely you may use 0 for "yes" and 1 for "no" :)
– xakepp35
20 hours ago
add a comment |
05AB1E, 9 bytes
{Rƶ.ssè›ß
Try it online or verify all test cases.
Port of @JonathanAllan's Jelly answer, so also takes the inputs x T M
and outputs 0
for "yes"
and 1
for "no"
. If this is not allowed, and it should be inverted, a trailing _
can be added.
Explanation:
{ # Sort the (implicit) input `x`
# i.e. `x`=[100,50,77,22,14,45] → [14,22,45,50,77,100]
R # Reverse it
# i.e. [14,22,45,50,77,100] → [100,77,50,45,22,14]
ƶ # Multiply it by it's 1-indexed range
# i.e. [100,77,50,45,22,14] → [100,154,150,180,110,84]
.s # Get all the suffices of this list
# i.e. [100,154,150,180,110,84]
# → [[84],[110,84],[180,110,84],[150,180,110,84],[100,154,150,180,110,84]]
s # Swap to take the (implicit) input `T`
è # Get the prefix at index `T`
# i.e. [[84],[110,84],[180,110,84],[150,180,110,84],[100,154,150,180,110,84]]
# and `T=3` → [150,180,110,84]
› # Check for each list-value if the (implicit) input `M` is larger than it
# i.e. [150,180,110,84] and `M`=180 → [1,0,1,1]
ß # And pop and push the minimum value in the list (which is output implicitly)
# i.e. [1,0,1,1] → 0
Alternative for .ssè
:
sG¦}
Try it online or verify all test cases.
Explanation:
s # Swap to take the (implicit) input `T`
G } # Loop `T-1` times:
¦ # Remove the first item from the list that many times
# i.e. [100,154,150,180,110,84] and `T=3` → [150,180,110,84]
05AB1E, 9 bytes
{Rƶ.ssè›ß
Try it online or verify all test cases.
Port of @JonathanAllan's Jelly answer, so also takes the inputs x T M
and outputs 0
for "yes"
and 1
for "no"
. If this is not allowed, and it should be inverted, a trailing _
can be added.
Explanation:
{ # Sort the (implicit) input `x`
# i.e. `x`=[100,50,77,22,14,45] → [14,22,45,50,77,100]
R # Reverse it
# i.e. [14,22,45,50,77,100] → [100,77,50,45,22,14]
ƶ # Multiply it by it's 1-indexed range
# i.e. [100,77,50,45,22,14] → [100,154,150,180,110,84]
.s # Get all the suffices of this list
# i.e. [100,154,150,180,110,84]
# → [[84],[110,84],[180,110,84],[150,180,110,84],[100,154,150,180,110,84]]
s # Swap to take the (implicit) input `T`
è # Get the prefix at index `T`
# i.e. [[84],[110,84],[180,110,84],[150,180,110,84],[100,154,150,180,110,84]]
# and `T=3` → [150,180,110,84]
› # Check for each list-value if the (implicit) input `M` is larger than it
# i.e. [150,180,110,84] and `M`=180 → [1,0,1,1]
ß # And pop and push the minimum value in the list (which is output implicitly)
# i.e. [1,0,1,1] → 0
Alternative for .ssè
:
sG¦}
Try it online or verify all test cases.
Explanation:
s # Swap to take the (implicit) input `T`
G } # Loop `T-1` times:
¦ # Remove the first item from the list that many times
# i.e. [100,154,150,180,110,84] and `T=3` → [150,180,110,84]
edited 20 hours ago
answered 21 hours ago
Kevin CruijssenKevin Cruijssen
36k554189
36k554189
1
I didn't stated on "how should you map output", just that it have to be boolean (to has only 2 states). So yes, definetely you may use 0 for "yes" and 1 for "no" :)
– xakepp35
20 hours ago
add a comment |
1
I didn't stated on "how should you map output", just that it have to be boolean (to has only 2 states). So yes, definetely you may use 0 for "yes" and 1 for "no" :)
– xakepp35
20 hours ago
1
1
I didn't stated on "how should you map output", just that it have to be boolean (to has only 2 states). So yes, definetely you may use 0 for "yes" and 1 for "no" :)
– xakepp35
20 hours ago
I didn't stated on "how should you map output", just that it have to be boolean (to has only 2 states). So yes, definetely you may use 0 for "yes" and 1 for "no" :)
– xakepp35
20 hours ago
add a comment |
C# (Visual C# Interactive Compiler), 83 bytes
(n,x,t,m)=>n>=m&&new int[n-m+1].Where((_,b)=>x.Count(a=>a>=t/(b+m))>=b+m).Count()>0
Short-circuiting AND (&&
) is needed, or else if m > n
, the array will be initialized with a negative number. Uses a different algorithm than the other existing submissions.
// Takes in 4 parameters as input
(n,x,t,m)=>
// Is n greater than or equal to m?
n>=m
// If it isn't, stop right there and return false. If it is, continue
&&
// Create a new array with the length of all the numbers from m to n, inclusive
new int[n-m+1]
// And filter the results by
.Where((_,b)=>
// If the number of people that invested more than the total amount divided by the index plus m
x.Count(a=>a>=t/(b+m))
// Is greater than the index plus m
>= b+m)
// And check if there is at least one value in the filtered IEnumerable<int>, and if there is, return true
.Count()>0
Try it online!
66? - Although once again cursed by Enumerable.Range :)
– dana
22 hours ago
I thought of that, and stated in the description that N>=1, and M<=N So you may shorten your solution a bit :)
– xakepp35
20 hours ago
add a comment |
C# (Visual C# Interactive Compiler), 83 bytes
(n,x,t,m)=>n>=m&&new int[n-m+1].Where((_,b)=>x.Count(a=>a>=t/(b+m))>=b+m).Count()>0
Short-circuiting AND (&&
) is needed, or else if m > n
, the array will be initialized with a negative number. Uses a different algorithm than the other existing submissions.
// Takes in 4 parameters as input
(n,x,t,m)=>
// Is n greater than or equal to m?
n>=m
// If it isn't, stop right there and return false. If it is, continue
&&
// Create a new array with the length of all the numbers from m to n, inclusive
new int[n-m+1]
// And filter the results by
.Where((_,b)=>
// If the number of people that invested more than the total amount divided by the index plus m
x.Count(a=>a>=t/(b+m))
// Is greater than the index plus m
>= b+m)
// And check if there is at least one value in the filtered IEnumerable<int>, and if there is, return true
.Count()>0
Try it online!
66? - Although once again cursed by Enumerable.Range :)
– dana
22 hours ago
I thought of that, and stated in the description that N>=1, and M<=N So you may shorten your solution a bit :)
– xakepp35
20 hours ago
add a comment |
C# (Visual C# Interactive Compiler), 83 bytes
(n,x,t,m)=>n>=m&&new int[n-m+1].Where((_,b)=>x.Count(a=>a>=t/(b+m))>=b+m).Count()>0
Short-circuiting AND (&&
) is needed, or else if m > n
, the array will be initialized with a negative number. Uses a different algorithm than the other existing submissions.
// Takes in 4 parameters as input
(n,x,t,m)=>
// Is n greater than or equal to m?
n>=m
// If it isn't, stop right there and return false. If it is, continue
&&
// Create a new array with the length of all the numbers from m to n, inclusive
new int[n-m+1]
// And filter the results by
.Where((_,b)=>
// If the number of people that invested more than the total amount divided by the index plus m
x.Count(a=>a>=t/(b+m))
// Is greater than the index plus m
>= b+m)
// And check if there is at least one value in the filtered IEnumerable<int>, and if there is, return true
.Count()>0
Try it online!
C# (Visual C# Interactive Compiler), 83 bytes
(n,x,t,m)=>n>=m&&new int[n-m+1].Where((_,b)=>x.Count(a=>a>=t/(b+m))>=b+m).Count()>0
Short-circuiting AND (&&
) is needed, or else if m > n
, the array will be initialized with a negative number. Uses a different algorithm than the other existing submissions.
// Takes in 4 parameters as input
(n,x,t,m)=>
// Is n greater than or equal to m?
n>=m
// If it isn't, stop right there and return false. If it is, continue
&&
// Create a new array with the length of all the numbers from m to n, inclusive
new int[n-m+1]
// And filter the results by
.Where((_,b)=>
// If the number of people that invested more than the total amount divided by the index plus m
x.Count(a=>a>=t/(b+m))
// Is greater than the index plus m
>= b+m)
// And check if there is at least one value in the filtered IEnumerable<int>, and if there is, return true
.Count()>0
Try it online!
edited yesterday
answered yesterday
Embodiment of IgnoranceEmbodiment of Ignorance
586115
586115
66? - Although once again cursed by Enumerable.Range :)
– dana
22 hours ago
I thought of that, and stated in the description that N>=1, and M<=N So you may shorten your solution a bit :)
– xakepp35
20 hours ago
add a comment |
66? - Although once again cursed by Enumerable.Range :)
– dana
22 hours ago
I thought of that, and stated in the description that N>=1, and M<=N So you may shorten your solution a bit :)
– xakepp35
20 hours ago
66? - Although once again cursed by Enumerable.Range :)
– dana
22 hours ago
66? - Although once again cursed by Enumerable.Range :)
– dana
22 hours ago
I thought of that, and stated in the description that N>=1, and M<=N So you may shorten your solution a bit :)
– xakepp35
20 hours ago
I thought of that, and stated in the description that N>=1, and M<=N So you may shorten your solution a bit :)
– xakepp35
20 hours ago
add a comment |
JavaScript, 54 52 bytes
(x,t,m,n)=>x.sort((a,b)=>a-b).some(i=>i*n-->=t&n>=m)
Try it online
Also 35-40% more performant that 72-byted solution. Lovely code, felt like its ready to be embedded in production MLM-related web projects :^)
– xakepp35
20 hours ago
add a comment |
JavaScript, 54 52 bytes
(x,t,m,n)=>x.sort((a,b)=>a-b).some(i=>i*n-->=t&n>=m)
Try it online
Also 35-40% more performant that 72-byted solution. Lovely code, felt like its ready to be embedded in production MLM-related web projects :^)
– xakepp35
20 hours ago
add a comment |
JavaScript, 54 52 bytes
(x,t,m,n)=>x.sort((a,b)=>a-b).some(i=>i*n-->=t&n>=m)
Try it online
JavaScript, 54 52 bytes
(x,t,m,n)=>x.sort((a,b)=>a-b).some(i=>i*n-->=t&n>=m)
Try it online
edited yesterday
answered yesterday
ShaggyShaggy
19.1k21666
19.1k21666
Also 35-40% more performant that 72-byted solution. Lovely code, felt like its ready to be embedded in production MLM-related web projects :^)
– xakepp35
20 hours ago
add a comment |
Also 35-40% more performant that 72-byted solution. Lovely code, felt like its ready to be embedded in production MLM-related web projects :^)
– xakepp35
20 hours ago
Also 35-40% more performant that 72-byted solution. Lovely code, felt like its ready to be embedded in production MLM-related web projects :^)
– xakepp35
20 hours ago
Also 35-40% more performant that 72-byted solution. Lovely code, felt like its ready to be embedded in production MLM-related web projects :^)
– xakepp35
20 hours ago
add a comment |
Retina, 79 bytes
d+
*
O^`_+(?=.*])
_+(?=.*])(?<=(W+_+)+)
$#1*$&
+`W+_+(.*_)_$
$1
(_+).*], 1,
Try it online! Takes input in the format [x], T, M
. Link includes test cases. Explanation:
d+
*
Convert to unary.
O^`_+(?=.*])
Sort [x]
in descending order.
_+(?=.*])(?<=(W+_+)+)
$#1*$&
Multiply each element of [x]
by its index.
+`W+_+(.*_)_$
$1
Delete the first M-1
elements of [x]
.
(_+).*], 1,
Test whether any remaining element of [x]
is greater or equal to T
.
add a comment |
Retina, 79 bytes
d+
*
O^`_+(?=.*])
_+(?=.*])(?<=(W+_+)+)
$#1*$&
+`W+_+(.*_)_$
$1
(_+).*], 1,
Try it online! Takes input in the format [x], T, M
. Link includes test cases. Explanation:
d+
*
Convert to unary.
O^`_+(?=.*])
Sort [x]
in descending order.
_+(?=.*])(?<=(W+_+)+)
$#1*$&
Multiply each element of [x]
by its index.
+`W+_+(.*_)_$
$1
Delete the first M-1
elements of [x]
.
(_+).*], 1,
Test whether any remaining element of [x]
is greater or equal to T
.
add a comment |
Retina, 79 bytes
d+
*
O^`_+(?=.*])
_+(?=.*])(?<=(W+_+)+)
$#1*$&
+`W+_+(.*_)_$
$1
(_+).*], 1,
Try it online! Takes input in the format [x], T, M
. Link includes test cases. Explanation:
d+
*
Convert to unary.
O^`_+(?=.*])
Sort [x]
in descending order.
_+(?=.*])(?<=(W+_+)+)
$#1*$&
Multiply each element of [x]
by its index.
+`W+_+(.*_)_$
$1
Delete the first M-1
elements of [x]
.
(_+).*], 1,
Test whether any remaining element of [x]
is greater or equal to T
.
Retina, 79 bytes
d+
*
O^`_+(?=.*])
_+(?=.*])(?<=(W+_+)+)
$#1*$&
+`W+_+(.*_)_$
$1
(_+).*], 1,
Try it online! Takes input in the format [x], T, M
. Link includes test cases. Explanation:
d+
*
Convert to unary.
O^`_+(?=.*])
Sort [x]
in descending order.
_+(?=.*])(?<=(W+_+)+)
$#1*$&
Multiply each element of [x]
by its index.
+`W+_+(.*_)_$
$1
Delete the first M-1
elements of [x]
.
(_+).*], 1,
Test whether any remaining element of [x]
is greater or equal to T
.
answered yesterday
NeilNeil
79.6k744177
79.6k744177
add a comment |
add a comment |
Perl 6, 46 33 29 bytes
{$^b>all $^a.sort Z*[...] @_}
Try it online!
Anonymous code blocks that takes input in the form list, amount, length of list, minimum amount of investors
and returns a truthy/falsey all
Junction, where truthy is failed and falsey is success.
Explanation:
{ } # Anonymous code block
all # Are all of
$^a.sort # The sorted list
Z* # Zip multiplied by
[...] @_ # The range from length of list to the minimum amount
$^b> # Not smaller than the given amount?
add a comment |
Perl 6, 46 33 29 bytes
{$^b>all $^a.sort Z*[...] @_}
Try it online!
Anonymous code blocks that takes input in the form list, amount, length of list, minimum amount of investors
and returns a truthy/falsey all
Junction, where truthy is failed and falsey is success.
Explanation:
{ } # Anonymous code block
all # Are all of
$^a.sort # The sorted list
Z* # Zip multiplied by
[...] @_ # The range from length of list to the minimum amount
$^b> # Not smaller than the given amount?
add a comment |
Perl 6, 46 33 29 bytes
{$^b>all $^a.sort Z*[...] @_}
Try it online!
Anonymous code blocks that takes input in the form list, amount, length of list, minimum amount of investors
and returns a truthy/falsey all
Junction, where truthy is failed and falsey is success.
Explanation:
{ } # Anonymous code block
all # Are all of
$^a.sort # The sorted list
Z* # Zip multiplied by
[...] @_ # The range from length of list to the minimum amount
$^b> # Not smaller than the given amount?
Perl 6, 46 33 29 bytes
{$^b>all $^a.sort Z*[...] @_}
Try it online!
Anonymous code blocks that takes input in the form list, amount, length of list, minimum amount of investors
and returns a truthy/falsey all
Junction, where truthy is failed and falsey is success.
Explanation:
{ } # Anonymous code block
all # Are all of
$^a.sort # The sorted list
Z* # Zip multiplied by
[...] @_ # The range from length of list to the minimum amount
$^b> # Not smaller than the given amount?
edited 17 hours ago
answered 21 hours ago
Jo KingJo King
21k248110
21k248110
add a comment |
add a comment |
05AB1E, 6 bytes
Input taken in the order T
, N
, x
, M
Output is 0
for peer reward and 1
if not
Ÿs{*›W
Try it online!
or as a Test Suite
Explanation
Ÿ # push the range [N ... T]
s{ # push the list x sorted ascending
* # elementwise multiplication (crops to shortest list)
› # for each element, check if M is greater than it
W # push min of the result
# output implicitly
Nice trick of using*
with the range to implicitly crop the list!
– Kevin Cruijssen
15 hours ago
add a comment |
05AB1E, 6 bytes
Input taken in the order T
, N
, x
, M
Output is 0
for peer reward and 1
if not
Ÿs{*›W
Try it online!
or as a Test Suite
Explanation
Ÿ # push the range [N ... T]
s{ # push the list x sorted ascending
* # elementwise multiplication (crops to shortest list)
› # for each element, check if M is greater than it
W # push min of the result
# output implicitly
Nice trick of using*
with the range to implicitly crop the list!
– Kevin Cruijssen
15 hours ago
add a comment |
05AB1E, 6 bytes
Input taken in the order T
, N
, x
, M
Output is 0
for peer reward and 1
if not
Ÿs{*›W
Try it online!
or as a Test Suite
Explanation
Ÿ # push the range [N ... T]
s{ # push the list x sorted ascending
* # elementwise multiplication (crops to shortest list)
› # for each element, check if M is greater than it
W # push min of the result
# output implicitly
05AB1E, 6 bytes
Input taken in the order T
, N
, x
, M
Output is 0
for peer reward and 1
if not
Ÿs{*›W
Try it online!
or as a Test Suite
Explanation
Ÿ # push the range [N ... T]
s{ # push the list x sorted ascending
* # elementwise multiplication (crops to shortest list)
› # for each element, check if M is greater than it
W # push min of the result
# output implicitly
edited 16 hours ago
answered 16 hours ago
EmignaEmigna
45.5k432138
45.5k432138
Nice trick of using*
with the range to implicitly crop the list!
– Kevin Cruijssen
15 hours ago
add a comment |
Nice trick of using*
with the range to implicitly crop the list!
– Kevin Cruijssen
15 hours ago
Nice trick of using
*
with the range to implicitly crop the list!– Kevin Cruijssen
15 hours ago
Nice trick of using
*
with the range to implicitly crop the list!– Kevin Cruijssen
15 hours ago
add a comment |
JavaScript, 72 bytes
Code
(x,T,M)=>x.sort(t=(d,e)=>e-d).map((s,i)=>s*i+s).slice(M-1).sort(t)[0]>=T
Try it online!
Accepts input in format (x,T,M)
Explanation
x.sort(t=(d,e)=>e-d) \sort numbers in reverse numerical order
.map((s,i)=>s*i+s) \Multiply each number in array by position(1 indexed) in array
.slice(M-1) \Remove the first M-1 elements (at least M people)
.sort(t)[0] \Get the maximum value in the array
>=T \True if the maximum value is >= the threshold
54 bytes?
– Arnauld
yesterday
(Or 53 bytes if the meaning of the Boolean value can be inverted.)
– Arnauld
yesterday
@Arnauld, 52 bytes ;)
– Shaggy
yesterday
(By the way, I came up with my solution independently of your comment, in case you were wondering - it's a port of my Japt solution. On mobile so can't see timestamps properly to tell who posted first.)
– Shaggy
yesterday
add a comment |
JavaScript, 72 bytes
Code
(x,T,M)=>x.sort(t=(d,e)=>e-d).map((s,i)=>s*i+s).slice(M-1).sort(t)[0]>=T
Try it online!
Accepts input in format (x,T,M)
Explanation
x.sort(t=(d,e)=>e-d) \sort numbers in reverse numerical order
.map((s,i)=>s*i+s) \Multiply each number in array by position(1 indexed) in array
.slice(M-1) \Remove the first M-1 elements (at least M people)
.sort(t)[0] \Get the maximum value in the array
>=T \True if the maximum value is >= the threshold
54 bytes?
– Arnauld
yesterday
(Or 53 bytes if the meaning of the Boolean value can be inverted.)
– Arnauld
yesterday
@Arnauld, 52 bytes ;)
– Shaggy
yesterday
(By the way, I came up with my solution independently of your comment, in case you were wondering - it's a port of my Japt solution. On mobile so can't see timestamps properly to tell who posted first.)
– Shaggy
yesterday
add a comment |
JavaScript, 72 bytes
Code
(x,T,M)=>x.sort(t=(d,e)=>e-d).map((s,i)=>s*i+s).slice(M-1).sort(t)[0]>=T
Try it online!
Accepts input in format (x,T,M)
Explanation
x.sort(t=(d,e)=>e-d) \sort numbers in reverse numerical order
.map((s,i)=>s*i+s) \Multiply each number in array by position(1 indexed) in array
.slice(M-1) \Remove the first M-1 elements (at least M people)
.sort(t)[0] \Get the maximum value in the array
>=T \True if the maximum value is >= the threshold
JavaScript, 72 bytes
Code
(x,T,M)=>x.sort(t=(d,e)=>e-d).map((s,i)=>s*i+s).slice(M-1).sort(t)[0]>=T
Try it online!
Accepts input in format (x,T,M)
Explanation
x.sort(t=(d,e)=>e-d) \sort numbers in reverse numerical order
.map((s,i)=>s*i+s) \Multiply each number in array by position(1 indexed) in array
.slice(M-1) \Remove the first M-1 elements (at least M people)
.sort(t)[0] \Get the maximum value in the array
>=T \True if the maximum value is >= the threshold
edited yesterday
answered yesterday
fəˈnɛtɪkfəˈnɛtɪk
3,5931537
3,5931537
54 bytes?
– Arnauld
yesterday
(Or 53 bytes if the meaning of the Boolean value can be inverted.)
– Arnauld
yesterday
@Arnauld, 52 bytes ;)
– Shaggy
yesterday
(By the way, I came up with my solution independently of your comment, in case you were wondering - it's a port of my Japt solution. On mobile so can't see timestamps properly to tell who posted first.)
– Shaggy
yesterday
add a comment |
54 bytes?
– Arnauld
yesterday
(Or 53 bytes if the meaning of the Boolean value can be inverted.)
– Arnauld
yesterday
@Arnauld, 52 bytes ;)
– Shaggy
yesterday
(By the way, I came up with my solution independently of your comment, in case you were wondering - it's a port of my Japt solution. On mobile so can't see timestamps properly to tell who posted first.)
– Shaggy
yesterday
54 bytes?
– Arnauld
yesterday
54 bytes?
– Arnauld
yesterday
(Or 53 bytes if the meaning of the Boolean value can be inverted.)
– Arnauld
yesterday
(Or 53 bytes if the meaning of the Boolean value can be inverted.)
– Arnauld
yesterday
@Arnauld, 52 bytes ;)
– Shaggy
yesterday
@Arnauld, 52 bytes ;)
– Shaggy
yesterday
(By the way, I came up with my solution independently of your comment, in case you were wondering - it's a port of my Japt solution. On mobile so can't see timestamps properly to tell who posted first.)
– Shaggy
yesterday
(By the way, I came up with my solution independently of your comment, in case you were wondering - it's a port of my Japt solution. On mobile so can't see timestamps properly to tell who posted first.)
– Shaggy
yesterday
add a comment |
Python 3, 136 bytes
Just tests the conditions to make sure they are met. 1 if the reward is given, 0 if not.
lambda N,x,T,M:(sum(x)>=T)*(M<=N)*any(any(all(j>=T/k for j in i)for i in combinations(x,k))for k in range(M,N+1))
from itertools import*
Try it online!
add a comment |
Python 3, 136 bytes
Just tests the conditions to make sure they are met. 1 if the reward is given, 0 if not.
lambda N,x,T,M:(sum(x)>=T)*(M<=N)*any(any(all(j>=T/k for j in i)for i in combinations(x,k))for k in range(M,N+1))
from itertools import*
Try it online!
add a comment |
Python 3, 136 bytes
Just tests the conditions to make sure they are met. 1 if the reward is given, 0 if not.
lambda N,x,T,M:(sum(x)>=T)*(M<=N)*any(any(all(j>=T/k for j in i)for i in combinations(x,k))for k in range(M,N+1))
from itertools import*
Try it online!
Python 3, 136 bytes
Just tests the conditions to make sure they are met. 1 if the reward is given, 0 if not.
lambda N,x,T,M:(sum(x)>=T)*(M<=N)*any(any(all(j>=T/k for j in i)for i in combinations(x,k))for k in range(M,N+1))
from itertools import*
Try it online!
edited yesterday
answered yesterday
Neil A.Neil A.
1,208120
1,208120
add a comment |
add a comment |
Python, 71 65 bytes
lambda x,T,M:all(i*v<T for i,v in enumerate(sorted(x)[-M::-1],M))
Try it online!
An unnamed function; port of my Jelly answer. As such "yes" is False
and "no" is True
. Here, however, we discard test-cases as a part of the reversal and take advantage of the ability to initiate the enumerate
count to M
. (min
would also work in place of all
)
add a comment |
Python, 71 65 bytes
lambda x,T,M:all(i*v<T for i,v in enumerate(sorted(x)[-M::-1],M))
Try it online!
An unnamed function; port of my Jelly answer. As such "yes" is False
and "no" is True
. Here, however, we discard test-cases as a part of the reversal and take advantage of the ability to initiate the enumerate
count to M
. (min
would also work in place of all
)
add a comment |
Python, 71 65 bytes
lambda x,T,M:all(i*v<T for i,v in enumerate(sorted(x)[-M::-1],M))
Try it online!
An unnamed function; port of my Jelly answer. As such "yes" is False
and "no" is True
. Here, however, we discard test-cases as a part of the reversal and take advantage of the ability to initiate the enumerate
count to M
. (min
would also work in place of all
)
Python, 71 65 bytes
lambda x,T,M:all(i*v<T for i,v in enumerate(sorted(x)[-M::-1],M))
Try it online!
An unnamed function; port of my Jelly answer. As such "yes" is False
and "no" is True
. Here, however, we discard test-cases as a part of the reversal and take advantage of the ability to initiate the enumerate
count to M
. (min
would also work in place of all
)
edited yesterday
answered yesterday
Jonathan AllanJonathan Allan
51k534166
51k534166
add a comment |
add a comment |
R, 43 42 bytes
-1 bytes by implementing the approach even more closely
function(N,x,S,M)min(sort(x,T)[M:N]*M:N<S)
Try it online!
Simple R implementation of Jonathan's Jelly approach. I tried a bunch of variations but this pips the best I could think of by a few bytes.
1 implies failure, 0 implies success.
add a comment |
R, 43 42 bytes
-1 bytes by implementing the approach even more closely
function(N,x,S,M)min(sort(x,T)[M:N]*M:N<S)
Try it online!
Simple R implementation of Jonathan's Jelly approach. I tried a bunch of variations but this pips the best I could think of by a few bytes.
1 implies failure, 0 implies success.
add a comment |
R, 43 42 bytes
-1 bytes by implementing the approach even more closely
function(N,x,S,M)min(sort(x,T)[M:N]*M:N<S)
Try it online!
Simple R implementation of Jonathan's Jelly approach. I tried a bunch of variations but this pips the best I could think of by a few bytes.
1 implies failure, 0 implies success.
R, 43 42 bytes
-1 bytes by implementing the approach even more closely
function(N,x,S,M)min(sort(x,T)[M:N]*M:N<S)
Try it online!
Simple R implementation of Jonathan's Jelly approach. I tried a bunch of variations but this pips the best I could think of by a few bytes.
1 implies failure, 0 implies success.
answered 17 hours ago
CriminallyVulgarCriminallyVulgar
1815
1815
add a comment |
add a comment |
C# (.NET Core), 129 bytes
Without LINQ.
(n,q,t,m)=>{int c=0;for(var k=m;k<=q.Length;){for(var j=0;j<q.Length;){if(q[j++]>=t/k)c++;}c=c>=k++?1:0;if(c>0)break;}return c;};
Try it online!
add a comment |
C# (.NET Core), 129 bytes
Without LINQ.
(n,q,t,m)=>{int c=0;for(var k=m;k<=q.Length;){for(var j=0;j<q.Length;){if(q[j++]>=t/k)c++;}c=c>=k++?1:0;if(c>0)break;}return c;};
Try it online!
add a comment |
C# (.NET Core), 129 bytes
Without LINQ.
(n,q,t,m)=>{int c=0;for(var k=m;k<=q.Length;){for(var j=0;j<q.Length;){if(q[j++]>=t/k)c++;}c=c>=k++?1:0;if(c>0)break;}return c;};
Try it online!
C# (.NET Core), 129 bytes
Without LINQ.
(n,q,t,m)=>{int c=0;for(var k=m;k<=q.Length;){for(var j=0;j<q.Length;){if(q[j++]>=t/k)c++;}c=c>=k++?1:0;if(c>0)break;}return c;};
Try it online!
answered 11 hours ago
DestroigoDestroigo
913
913
add a comment |
add a comment |
Japt, 16 14 13 11 bytes
ñ í*WõX)d¨V
Try it
ñ í*WõX)d¨V
:Implicit input of array U=x and integers V=T, W=M & X=N
ñ :Sort U
í :Interleave with
WõX : Range [W,X]
* : And reduce each pair of elements by multiplication
) :End interleaving
d :Any
¨V : Greater than or equal to V
add a comment |
Japt, 16 14 13 11 bytes
ñ í*WõX)d¨V
Try it
ñ í*WõX)d¨V
:Implicit input of array U=x and integers V=T, W=M & X=N
ñ :Sort U
í :Interleave with
WõX : Range [W,X]
* : And reduce each pair of elements by multiplication
) :End interleaving
d :Any
¨V : Greater than or equal to V
add a comment |
Japt, 16 14 13 11 bytes
ñ í*WõX)d¨V
Try it
ñ í*WõX)d¨V
:Implicit input of array U=x and integers V=T, W=M & X=N
ñ :Sort U
í :Interleave with
WõX : Range [W,X]
* : And reduce each pair of elements by multiplication
) :End interleaving
d :Any
¨V : Greater than or equal to V
Japt, 16 14 13 11 bytes
ñ í*WõX)d¨V
Try it
ñ í*WõX)d¨V
:Implicit input of array U=x and integers V=T, W=M & X=N
ñ :Sort U
í :Interleave with
WõX : Range [W,X]
* : And reduce each pair of elements by multiplication
) :End interleaving
d :Any
¨V : Greater than or equal to V
edited 11 hours ago
answered yesterday
ShaggyShaggy
19.1k21666
19.1k21666
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f178443%2fmulti-level-marketing-legs-investment-rule%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
N
is implied bylen(x)
, I suppose we can but do not have to take it as an input, right?– Jonathan Allan
yesterday
1
@JonathanAllan Sure, if your language allows it, and writing
len(x)
will be shorter than writingN
. That is made, because for dynamically allocated arrayx
in C there is no directlen(x)
function - so you may always refer to length asN
. For convenience, you may consider all input dataN, x, T, M
as some externally defined constants, or some language built-ins.– xakepp35
yesterday
1
I don't think those notifications reached them (with the hyphens) as I got them in my inbox.
– Jonathan Allan
yesterday
1
@JonathanAllan not quite familar with pinging syntax, and non-latin names.. maybe they will return some day :)
– xakepp35
yesterday
1
Also, can output be reversed? A falsey value for
true
and truthy value forfalse
?– Shaggy
yesterday