The Perl Review's April Golf Challenge has begun. This month's challenge is a variation of the anagram problem from Jon Bentley's Programming Pearls.

There is already quite a race developing to see who can break the 100 stroke barrier. Check the leaderboard to track tournament developments.

Enjoy!
--Dave

Update: Please do not post your solutions here

Replies are listed 'Best First'.
Re: TPR(0,2) Begins
by dragonchild (Archbishop) on Apr 08, 2002 at 15:07 UTC
    Wow. This was a neat problem. I'd like to post my solution (which came in really abysmally) and MeowChow's solution, which was the leader till this weekend. Just reading this one game me a ton of new tricks.

    I managed to get to 92 characters with the following:

    map$j{join'',sort/./g}.=$_,sort<>;map{/^[^a]/&&print$'}sort map{(a..t) +[s!$/(?=.)! !g].$_}%j
    I was miffed that I couldn't get to 80 or less, but it was better than the 120+ I originally had.

    Then I looked at MeowChow's.

    $o{_,sort/./g}=~s/.*/_$& $_/for sort<>;print/__ (.* )/for sort%o
    And, yes, that carriage return after the .* is necessary. I'm like, Ouch! The tricks in this one.
    1. I'd been struggling to remove the join in my hashkey. I couldn't figure out how to force stringification on the sort without having it hit scalar context first. I completely forgot to look at multiple keys.
    2. I started in with the GRT so I could get everything to work with the default behavior of sort. The problem was that I was setting some letter, then having to remove that letter. That cost me, easily, 6+ characters. Instead, just concatenate some character as many times as you have words at the beginning, then strip that out later.

      The best thing about doing it this way is that you get to count while reading, instead of counting when preparing to write.

    3. I was stupid with the s!$/(?=.)! !g stuff. I forgot to use a carriage return within the substitution and didn't know how to use \b. *sighs*
    For those curious why MeowChow didn't do something with $' instead of adding the carriage return in the capture, remember that doing it that way would require two map/for's, not just one.

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

Re: TPR(0,2) Begins
by Juerd (Abbot) on Apr 01, 2002 at 16:10 UTC

    Please not anagrams again. This game has already been played a lot, including right here in the monastery (Search on Anagram).

    I liked the magic number challenge, but this gets boring.

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk
    

      The anagrams are only part of the competition. Yes, they've been covered here and elsewhere, but read the rules and you will see that a significant amount of calories will need to be expended on the sorting of the output.

      I hope you enjoy it despite your feelings of anagram-overload.