Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

57!
#!/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 - 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: (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,@_)}@_:[] }
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      Make that 48:
      sub p { @_?map{my$a=$_;map[$a,@$_],p(grep$_^$a,@_)}@_:[] }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://77830]
help
Chatterbox?
[marto]: "Eugenie Scott, executive director of the National Center for Science Education, dubbed this approach the Gish gallop, describing it as "where the creationist is allowed to run on for 45 minutes or an hour, spewing forth torrents of error that the
[marto]: evolutionist hasn't a prayer of refuting in the format of a debate." She also criticized Gish for failing to answer objections raised by his opponents"
[erix]: one would hope evolutionists haven't any prayers anyway
[marto]: obviously someone could be religious, but not creationist
[erix]: "Nothing in Intelligent Design makes sense except in the light of Creationism" <-- I made that one up myself (free after Dobzhansky )
[erix]: yes. Deplorable marto, deplorable.
[marto]: the situation seemed similar to this one, majority of the contributrions are nonsense, doesn't address any questions ...
[marto]: meh, I've been called worse :P

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2017-07-28 15:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (431 votes). Check out past polls.