Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Generator of integer partitionts of n

by chiburashka
on Aug 28, 2004 at 02:49 UTC ( #386542=note: print w/ replies, xml ) Need Help??


in reply to Re: Generator of integer partitionts of n
in thread Generator of integer partitionts of n

Thank you sooooooo much , that's Exactly what i was trying to do, but i need to get this output into an array somehow line by line, can you help just a little bit more please ?


Comment on Re^2: Generator of integer partitionts of n
Re^3: Generator of integer partitionts of n
by ikegami (Pope) on Aug 28, 2004 at 06:34 UTC
    my @p; sub part { my ($a, $k, $n, $t) = @_; $n = 2*$k unless (defined($n)); $t = 0 unless (defined($t)); $p[$t] = $k; push(@$a, [ @p[1..$#p] ]) if $n == $k; for (my $j = $k<$n-$k ? $k : $n-$k; $j >= 1; $j--) { part($a, $j, $n-$k, $t+1); } } my $integer = ...; my @a; part(\@a, $integer); print(join(" ", @$_), "\n") foreach (@a);
Re^3: Generator of integer partitionts of n
by tilly (Archbishop) on Aug 28, 2004 at 17:51 UTC
    Some random advice for you.

    Depending on what you're doing, you should reconsider your desire to keep this data in an array. As n grows, the data requirements for that array grow rapidly. Once you use up available RAM (which happens sooner than you'd think), you're in trouble.

    Changing your flow of control of your actual problem to avoid having to have it all in memory at once will let you calculate several more values of whatever you're trying to calculate.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://386542]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-12-28 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls