Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re (tilly) 2: (Golf as well): List of Partitions

by tilly (Archbishop)
on May 06, 2001 at 16:06 UTC ( #78343=note: print w/ replies, xml ) Need Help??

in reply to Re: (Golf as well): List of Partitions
in thread (Golf as well): List of Partitions

Cute idea, but your output from P(11) is..ambiguous.

And P(12) has the incorrect "1011" entry for 10, 11.

Nice improvement. It can indeed be compressed. Here is 74 characters:

sub P{ my$n=pop;[$n],map{my$i=$_;grep{!grep$_>$i,@$_}map[$i,@$_],P($n-$i)}1.. +$n-1 }

Comment on Re (tilly) 2: (Golf as well): List of Partitions
Download Code
Replies are listed 'Best First'.
Re: Re (tilly) 2: (Golf as well): List of Partitions
by danger (Priest) on May 07, 2001 at 00:52 UTC

    Hmm, and we can shave that down to 71 chars:

    sub P{ [@_],map{my$i=$_;grep{!grep$_>$i,@$_}map[$i,@$_],P($_[0]-$i)}1..$_[0]- +1 }
      Nice, now slimed down to 64 on the knowledge that the partitions are always sorted from largest number to smallest...
      sub P{ [@_],map{my$i=$_;map$$_[0]>$i?():[$i,@$_],P($_[0]-$i)}1..$_[0]-1 }
      Saved an additional char because my map could be commified.

      UPDATE 2
      Scraping the barrel for 61:

      sub P{ my$i;[@_],map{map$$_[0]>$i?():[$i,@$_],P($_[0]-++$i)}2..$_[0] }

        Tilly, i would say something, but it would sound clunky compared to the beautiful code above. It would be nice if i could ++ you more than once for that snippet.

        One question though, what's commified? i'm not sure if i've ever heard the term...


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2015-11-29 09:37 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (750 votes), past polls