Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: "Countdown" (golf)

by dragonchild (Archbishop)
on Nov 30, 2001 at 22:31 UTC ( [id://128695]=note: print w/replies, xml ) Need Help??


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

Modifying blakem's solution to do the longest yields 93 characters with
@_=sort@_;$"='?';push@{$,[length]},$_ for grep{(join'',sort split//)=~ +m!^$/@_?$!}<D>;@{pop@,}

Update: 92 characters.

@_=sort@_;$"='?';push@{$,[length]},$_ for grep{(join'',sort split//)=~ +m!$/@_?$!}<D>;@{pop@,}

Update2: 89 characters.

@_=sort@_;$"='?';push@{$,[length]},$_ for grep{(join'',sort/./sg)=~m!$ +/@_?$!}<D>;@{pop@,}

Update2: 88 characters.

perl -l @_=sort@_;$"='?';push@{$,[length]},$_ for grep{(join'',sort/./sg)=~/$\ +@_?$/}<D>;@{pop@,}

------
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.

Replies are listed 'Best First'.
Re: Re: Re: "Countdown" (golf)
by blakem (Monsignor) on Dec 01, 2001 at 07:47 UTC
    wow, that junk after the push is hard on the eyes... ;-)

    I really like the /./sg trick, but why use the /s? Getting rid of that newline has been one of the big obstacles on the course. Stealing this trick (w/o the /s) lets me get rid of the $/ $\ nonsense, shortening my return-the-whole-list code to 52 chars!

    # 1 2 3 4 5 #234567890123456789012345678901234567890123456789012 @_=sort@_;$"='?';grep{(join'',sort/./g)=~/^@_?$/}<D>

    -Blake

Re: Re: Re: "Countdown" (golf)
by stuffy (Monk) on Dec 01, 2001 at 08:17 UTC
    dragonchild
    your solution has the same problems as gbarr It only prints out the first of the longest words.

    Stuffy
    That's my story, and I'm sticking to it, unless I'm wrong in which case I will probably change it ;~)
    may be reproduced under the SDL
      I think you might want to recheck your tests... perhaps with your test there *is* only one longest word.

      For the list qw(a r t) both dragonchilds and gbarrs solutions produce 'art', 'tar', and 'rat' for me.

      -Blake

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2024-04-19 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found