Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: (Golf) Per Mutations

by Masem (Monsignor)
on May 04, 2001 at 03:03 UTC ( #77830=note: print w/ replies, xml ) Need Help??

in reply to (Golf) Per Mutations


#!/usr/bin/perl -w use strict; use Data::Dumper; my @b = p(1,2,3,4); print Dumper( @b ); sub p { $#_<1?[@_]:map{my$a=$_;map{[$a,@$_]}p(grep{$_!=$a}@_)}@_ }

Dr. Michael K. Neylon - || "You've left the lens cap of your mind on again, Pinky" - The Brain

Comment on Re: (Golf) Per Mutations
Download Code
Replies are listed 'Best First'.
Re (tilly) 2: (Golf) Per Mutations
by tilly (Archbishop) on May 04, 2001 at 04:29 UTC
    Didn't the rules say arbitrary list? Try this with the list (1,2,3,1) and you get incorrect output.

    However here is another 57 char solution that does not suffer from this deficiency.

    sub p{ @_?map{my$x=shift;@r=map[$x,@$_],&p;push@_,$x;@r}1..@_:[] }
Re: Re: (Golf) Per Mutations
by MeowChow (Vicar) on May 04, 2001 at 03:46 UTC
    Awesome :) We can even bring that down to 49:
    sub p { @_?map{my$a=$_;map[$a,@$_],p(grep$_!=$a,@_)}@_:[] }
                   s aamecha.s a..a\u$&owag.print
      Make that 48:
      sub p { @_?map{my$a=$_;map[$a,@$_],p(grep$_^$a,@_)}@_:[] }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2015-11-25 23:43 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (693 votes), past polls