Live data from Hacker News

Ask HN: algorithm to slice a number into parts

news.ycombinator.com

11–15 of 15 posts

Re: Ask HN: algorithm to slice a number into parts

#12
Edit: 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

#13
if 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

Post reply on HN