protip: Use Generating functions. Piece of cake if you use them for this problem.
Ask HN: algorithm to slice a number into parts
11–15 of 15 posts
Re: Ask HN: algorithm to slice a number into parts
#12Edit: slices should be of distinct values.
You can't do it with positive integers if nWhy are you doing this? As someone else has said, this does smell of homework. If it is homework, then tell us what you've tried. If it isn't, then tell us what it's for.
You continue to underspecify your problem. What are you trying to achieve?
Re: Ask HN: algorithm to slice a number into parts
#13if interested in integer partitions this python should do the job
def intpart(n):
if n == 0:
yield []
for k in range(1,n+1):
for p in intpart(n-k):
yield [k] + p
i believe that this isn't truly integer partitions because it will count 4 = 1,1,2,1 and 1,1,1,2 as different partitions but that's all I can give you between breakfast and work.see wikipedia for integer partiton or young tableau for more on these interesting objects
Re: Ask HN: algorithm to slice a number into parts
#14write an algorithm that compute the factorial of a given whole number
Re: Ask HN: algorithm to slice a number into parts
#15how to write an algorithm