Probably a simple code-golf challenge. Given 2 positive integers m
and n
, make a list of n
values that are positive integers whose sum is equal to the number m
. Either all values in the output are the same value or the difference is exactly 1.
Examples
For example
m=6
andn=3
would become2, 2, 2
m=7
andn=3
would become2, 2, 3
or2, 3, 2
or3, 2, 2
m=7
andn=2
would become3, 4
or4, 3
m=7
andn=1
would become7
m=7
andn=8
would generate an error because the sum of 8 positive integers cannot be 7.m=10
andn=4
would become3, 3, 2, 2
or any other permutation
Rules
- Both input and output is only about positive integers.
- Either all values in the output are the same value or the difference is exactly 1.
- The order of the values in the list is not important.
- The sum of the values in the list is equal to
m
. - When it's not solvable, generate an error or a false value (in case of m=7 and n=8 for example).
- As a result of the other rules
m=8
andn=3
would generate any of the permutations of3, 3, 2
(not2, 2, 4
)
The winner
This is code-golf, so the shortest valid answer – measured in bytes – wins.
float a = -0f, b = 0f; System.out.println(a == b); System.out.println(a + "," + b);
... producestrue
and-0.0,0.0
. See, positive 0 and negative 0 are clearly two distinct number... the implementation says so! \$\endgroup\$