10
0
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
N
is implied bylen(x)
, I suppose we can but do not have to take it as an input, right? – Jonathan Allan – 2019-01-06T16:30:15.1271@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 – 2019-01-06T16:32:57.540@luis-mendo It's unclear "what is exactly unclear?" – xakepp35 – 2019-01-06T16:55:43.030
@erik-the-outgolfer Could you explain? – xakepp35 – 2019-01-06T16:55:54.623
1I don't think those notifications reached them (with the hyphens) as I got them in my inbox. – Jonathan Allan – 2019-01-06T17:03:22.767
1@JonathanAllan not quite familar with pinging syntax, and non-latin names.. maybe they will return some day :) – xakepp35 – 2019-01-06T17:17:58.917
It might be worth adding some test cases ...including some at edges like:
6, [100, 50, 77, 22, 14, 44], 180, 3
->0
; and6, [100, 50, 77, 22, 14, 45], 180, 3
->1
. – Jonathan Allan – 2019-01-06T17:48:09.293Does
M
have a minimum value? e.g. at least more than 0, or can it also be negative? – Embodiment of Ignorance – 2019-01-06T20:58:06.930Can
M
be 0-indexed? (i.e.,2
in each of the test cases) – Shaggy – 2019-01-06T22:51:34.8971Also, can output be reversed? A falsey value for
true
and truthy value forfalse
? – Shaggy – 2019-01-06T23:25:27.957@EmbodimentofIgnorance, I don't think it would be possible to have a negative number of investors! But the first part of your question does need answering; the current requirements that
M<=N>=1
do imply thatM
could be0
. – Shaggy – 2019-01-06T23:57:52.433Can't the second bullet point be more simply put as "Each investor must invest $T/N$"? If there is any $k$ that fulfills the requirements it holds that $k=N$ fulfills the requirement and of course the converse is trivial. Am I missing something? – Post Rock Garf Hunter – 2019-01-07T18:15:16.533
There also doesn't seem to be a winning criterion? – Post Rock Garf Hunter – 2019-01-07T18:17:36.867
1@WîtWisarhd Code golf is a winning criterion... look at the tags. – mbomb007 – 2019-01-08T00:47:33.080
@WitWisarhd Initially it was there, but was removed after a bit of thinking - it does distract away from real condition point, and it can be derived, (just check condition for a case k==N) – xakepp35 – 2019-01-08T09:41:20.613
I noticed the example for
N=5; M=3; T=10000
allows for 3 investors with 3334. This implies that "integer division" (i.e. round down) wouldn't work. Was this intentional? – dana – 2019-01-10T17:43:39.627