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

Re: Generator of integer partitionts of n

by BrowserUk (Patriarch)
on Aug 29, 2004 at 09:57 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-19 05:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found