Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-12-29 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (186 votes), past polls