in reply to (Golf as well): List of Partitions
Here's one that is 65 characters, returns as array of arrays, but has duplicates (though the orders are unique).
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Update: Same thing, but avoids repetitions: Total chars: 96sub P { $_[0]?map{my$c=$_;map[$c,@$_],P($_[0]-$c)}(1..$_[0]):[] }
sub P { my$b=$_[1]||$_[0]; $_[0]?map{my$c=$_;map[$c,@$_],P($_[0]-$c,$c)}grep{$_<=$b}(1..$_[0]):[] }
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
|
---|
Replies are listed 'Best First'. | |
---|---|
Re (tilly) 2 (non-recursive): (Golf as well): List of Partitions
by tilly (Archbishop) on May 06, 2001 at 20:39 UTC |
In Section
Seekers of Perl Wisdom