Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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 }

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 }
      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?
[stevieb]: 16.96 hours of runtime of a Raspberry Pi on a 12v, 7.2Ah battery :) Now to watch now long it takes to recharge the battery completely with my 18v solar cells in the sun :)
[stevieb]: my high-range estimate was 18 hours

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2017-03-26 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (315 votes). Check out past polls.