[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] The Perl Golf Apocalypse Experience



> BTW, Uri/Ron/Nathan, can you post the holes that were played during
> the contest? I would really like to try my hand at them in a more
> relaxed setting.

I don't remember most of them, and my memory of my favorite is a little shaky.
The basic idea was to substitute one character for another, but only inside of
parentheses. The parens were guaranteed to balance and to not nest. I don't
remember what the characters were, but assuming that it was to replace : with
- within parens (WLOG), the meat of my entry was:

    s/:(?=[^()]*\)/g

Although come to think of it, you could sacrfice a little efficiency and
remove the right paren from the character class. Right?

On the same subject, I was asked recently to think of a word which had 4
consecutive letters (like abcd or ghij). Failing miserably to think of one, I
decided it would be good for golf. The solution I came up with is pretty long,
and I bet a better one exists, so I'm throwing out the challenge.

perl -wne 'sub f{chr(ord($1)+pop)};print if/(.)(??{f(1)})(??{f(2)})(??{f(3)})/'
    /usr/dict/2words

BTW, no words that fit that pattern are in the standard Linux /usr/dict/words
-- I had to use a different word list that I found elsewhere.  But reasonably
common words that fit do exist.

-dlc


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe