Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Problems? Is your data what you think it is?
 
PerlMonks  

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.

UPDATE
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
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 }
      UPDATE
      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...

        jynx

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (18)
As of 2014-04-17 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (453 votes), past polls