e.g. n = (n1 + n2+ .. + nm)
where n is number and m no of slices.
n will be positive integer and m won't exceed 50.
Do you know any algorithm for this?Edit: slices should be of distinct values.
1–10 of 15 posts
e.g. n = (n1 + n2+ .. + nm)
where n is number and m no of slices.
n will be positive integer and m won't exceed 50.
Do you know any algorithm for this?Edit: slices should be of distinct values.
Another can be,
a) All Integers n1 = n2 = n3 =.....= n[m-1] = int(n / m) and nm = n - (n1 + n2 + n3 +.....+ n[m-1])
b) Floats n1 = n2 = n3 =.....= n[m] = n / m
I feel the problem can be more serious if you want the parts to be in certain fashion or distribution.
n1 = n2 = ... = n(m-1) = 0
nm = n
I'm sure that's not what you want.Here's another solution:
n1 = n2 = ... = nm = n/m
I'm sure that's not what you want either.Others have asked relevant questions. Assuming you want the numbers to be integers, and as equal as possible, then compute:
k_min = floor(n/m)
excess = n-k_min*m
All will be at least k_min. If they are all k_min, then you will have a total of k_min*m. You need an additional "excess", so assign them, one each, to the first bunch. n1 = k_min + 1
...
n(excess) = k_min + 1
n(excess+1) = k_min
...
nm = k_min
If you want you can reverse this so that the larger ones come after. That's left as an exercise for the interested reader.You could also put all the excess in one place, so you have
n1 = n2 = ... = n(m-1) = k_min
nm = k_min + excess
So really, it all depends on what you want.This is still fairly trivial.
I sense there are yet more requirements you're not telling us.
I think your problem description is missing something; otherwise n1 = n2 = n3 ... = n[m-1] = 1, nm = n - m + 1 is a trivial solution.
In that case, [1, 2, 3, ... m - 1, n - m*(m-1)/2] is a trivial solution.