Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

andye Re: "Countdown" (golf)

by andye (Curate)
on Nov 30, 2001 at 18:27 UTC ( [id://128623]=note: print w/replies, xml ) Need Help??


in reply to "Countdown" (golf)

Following blakem's rules,
# 1 2 3 #234567890123456789012345678901234567 $"='';grep{/^(([@_])(?!.*\2))+$/}<D>;
37 characters! I'm pleased with my first try at golfing. ;)

andy.

PS stuffy, good choice of puzzle! There went my lunchtime.

update: 36

#234567890123456789012345678901234567 $"='';grep/^(([@_])(?!.*\2))+$/,<D>;
update 2: Thanks dragonchild, 35 w/out the ;
Hmm... you're right about the duplicate letters. I can't remember whether these appear on the t.v. show - I rather suspect they do.

update, later:
This cope with duplicates, but is a lot longer:

# 1 2 3 4 5 6 7 + 8 #234567890123456789012345678901234567890123456789012345678901234567890 +12345678901 $"='';$n{$_}++for@_;grep/^((??{"([@_])"})(??{"(?!([^$1 ]*$1){$n{$1},}) +"}))+$/,<D>
(you need to use re 'eval')
I'd rather do:
$"='';$n{$_}++for@_;grep/^(([@_])(??{"(?!([^$1 ]*$1){$n{$1},})"}))+$/, +<D>
(the difference being that @_ is interpolated normally here), but for some reason this isn't allowed - I get back Eval-group in insecure regular expression in regex - no idea why, since I'm using re 'eval', and @_ surely can't be tainted?

Going to dinner. andy.

Replies are listed 'Best First'.
Re: andye Re: "Countdown" (golf)
by dragonchild (Archbishop) on Nov 30, 2001 at 18:41 UTC
    As always, removing the trailing semi-colon helps. :-)

    Excellent solution!

    Update: Of course (and this wasn't specified, so it's cool!) ... this won't work with duplicate letters. blakem's does, yours doesn't. I would suspect the gameshow, though it wouldn't say this, would never give dupes.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

      It can give dupes. In fact sometimes, the letters are so bad that the best the contestants can do is get a 4-letter word.

      I couldn't find the offical Countdown website on channel4.com. But there is more info about how the game is played here.

      Simon Flack ($code or die)
      $,=reverse'"ro_';s,$,\$,;s,$,lc ref sub{},e;$,
      =~y'_"' ';eval"die";print $_,lc substr$@,0,3;
Re: andye Re: "Countdown" (golf)
by blakem (Monsignor) on Dec 01, 2001 at 06:20 UTC
    I can shorten your 36 non-duplicate-letter attempt by 5 chars with:
    # 1 2 3 #234567890123456789012345678901 grep/^(([@_])(?!.*\2))+$/x,<D>;
    I think this trick might be applicable to your others as well...

    Update: I'm still trying to grok your longer ones (re eval in golf... coool) and I'm uncovering some oddities:

    qw(a d d) ad add dad qw(a d) ad add <= wrong... but 'dad' got correctly skipped... I think add gets through because the 'd's are right next to each other
    Doubled letters (dd, tt, etc) are sneaking through... It looks like $n{'d'} needs to be temporarilly decremented when 'd' matches in the character class...

    -Blake

      I can shorten your 36 non-duplicate-letter attempt by 5 chars with: /x instead of $"=''

      Clever!

      I'm not surprised the re eval ones don't work properly - I was getting some strange results while working them out. Also I was becoming confused! ;)

      andy.

Re: andye Re: "Countdown" (golf)
by dragonchild (Archbishop) on Dec 01, 2001 at 01:45 UTC
    I can't run your update using 5.6.0 on Solaris ... it says that there's an unmatched bracket...

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2024-04-23 11:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found