Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: "Countdown" (golf)

by japhy (Canon)
on Nov 30, 2001 at 14:19 UTC ( [id://128587]=note: print w/replies, xml ) Need Help??


in reply to Re: "Countdown" (golf)
in thread "Countdown" (golf)

I hate to take credit for this 3-character reduction...
$;=join'?',sort@_;grep{chop;(join'',sort split//)=~/^$;$/}<D>
Why were you sorting $; as well?

_____________________________________________________
Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Replies are listed 'Best First'.
Re: Re: Re: "Countdown" (golf)
by blakem (Monsignor) on Nov 30, 2001 at 15:11 UTC
    The regex needs a '?' on the end... Its the difference between /^a?b?c$/ and /a?b?c?$/. Looking at it again, I only need to add one char to get it back though: 62 chars
    # 1 2 3 4 5 6 #2345678901234567890123456789012345678901234567890123456789012 $;=join'?',sort@_;grep{chop;(join'',sort split//)=~/^$;?$/}<D>
    Ah, but I can get it back with a little rearranging.... 61 chars
    # 1 2 3 4 5 6 #234567890123456789012345678901234567890123456789012345678901 @_=sort@_;$"='?';grep{chop;(join'',sort split//)=~/^@_?$/}<D>

    -Blake

Re(3): "Countdown" (golf)
by graq (Curate) on Nov 30, 2001 at 15:13 UTC
    Why does neither of these return 'blade'?

    my @letters = qw(b a l d y a e y t);

    __PASTE__

    ~/perl_stuff> grep blade /usr/dict/words blade switchblade ~/perl_stuff> perl golf.pl aye baldy bay bayed beady bey by bye byte day delay dey dye lady lay lye y ye yea yet

    <a href="http://www.graq.co.uk">Graq</a>

      Check out my reply to japhy, and notice that all your results contain at least one 'y'.... Add the '?' to the end of the regex, and 'blade' will show up.

      -Blake

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-26 06:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found