Another deceptively easy challenge: compose a golfed sub that takes an arbitrary list, and returns a list of all arrays that are permutations of that list. My best attempt is currently 72 chars:
sub p {@_?do{my$x=pop;map{my@l=@$_;map[@l[0..$_-1],$x,@l[$_..$#l]],0..@l}&p}:[]} |
Extra Credit: Produce a non-recursive solution.p(1, 2, 3) should return: ( [3, 2, 1], [2, 3, 1], [2, 1, 3], [3, 1, 2], [1, 3, 2], [1, 2, 3] )
MeowChow s aamecha.s a..a\u$&owag.print
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (Golf) Per Mutations
by Masem (Monsignor) on May 04, 2001 at 03:03 UTC | |
by tilly (Archbishop) on May 04, 2001 at 04:29 UTC | |
by MeowChow (Vicar) on May 04, 2001 at 03:46 UTC | |
by dws (Chancellor) on May 04, 2001 at 03:59 UTC | |
Re: (Golf) Per Mutations
by Masem (Monsignor) on May 04, 2001 at 18:57 UTC | |
by tilly (Archbishop) on May 04, 2001 at 19:16 UTC | |
Re: (Golf) Per Mutations
by wardk (Deacon) on May 04, 2001 at 04:30 UTC | |
Re: (Golf) Per Mutations
by arhuman (Vicar) on May 04, 2001 at 02:09 UTC | |
by MeowChow (Vicar) on May 04, 2001 at 02:25 UTC | |
by arhuman (Vicar) on May 04, 2001 at 02:36 UTC |
Back to
Meditations