Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Generator of integer partitionts of n

by BrowserUk (Pope)
on Aug 29, 2004 at 09:57 UTC ( #386714=note: print w/ replies, xml ) Need Help??


in reply to Generator of integer partitionts of n

#! perl -slw use strict; sub xp{ [ @$_, 1 ], @$_ > 1 && $_->[ -1 ] < $_->[ -2 ] ? [ @$_[ 0 .. $#$_ -1 ], $_->[ -1 ]+1 ] : () } sub partitions { return unless $_[ 0 ]; map( xp, partitions( $_[ 0 ] - 1 ) ), [ $_[ 0 ] ]; } print "@$_" for partitions $ARGV[ 0 ]; __END__ P:\test>386531 6 1 1 1 1 1 1 2 1 1 1 1 2 2 1 1 2 2 2 3 1 1 1 3 2 1 3 3 4 1 1 4 2 5 1 6

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon


Comment on Re: Generator of integer partitionts of n
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2014-09-24 03:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (245 votes), past polls