Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The PGA was the Perl Golf Apocalypse at the 4th Perl Conference.

Uri Guttman has kindly sent me the questions in order to replay the tournament here at PerlMonks.

The tournament was arranged into 17 "holes". Each hole had a stated level of difficulty and a time limit. The time limit doesn't apply here but they have been left in as an indication of the pressure that the contestants were under.

The holes will be submitted in three rounds over three weeks. The PGA suggested solutions for each round will be published before each new round.

We can also turn this into a competition. Send me a /msg if you wish to take part. I will keep track of the scores over the whole course and setup a leadership table.

Even if you haven't played Perl Golf before you should try one or two of these. Dijkstra notwithstanding, Perl Golf is a good way to learn some of Perl's dustier features and if nothing else it will probably get you to read the perlrun manpage.


1. The aim of the tournament is the shortest solution on each hole. You should publish your score with each solution. Counting is as follows:
sub hole{print "hello, world"} For a sub 123456789_123456789_ 20 chars perl -e 'print "hello, world"' For a one liner 123456789_123456789_123456789_ 30 chars
2. "use strict" and -w are not required.

3. All subroutines which should return a single scalar value will be called in a scalar context.

Thanks again to Uri and the others who contributed to the PGA. Uri's Perl Golf page is here.

ROUND 1: Holes 1-6

Hole 1 - Fifth Word

Write a Perl subroutine which returns the fifth word in a string. A word is any sequence of letters, numbers, and/or underscores. The string will be passed as the sole argument and will contain at least 5 words.

* Difficulty: Easy

* Time: 3 minutes

Hole 2 - Error Message

Write a Perl one-liner that prints the following to STDERR:
Can't find label TPC at -e line 5.

* Difficulty: Easy

* Time: 3 minutes

Hole 3 - Smallest Repeating Pattern

Write a subroutine that accepts a string which may consist of a repeating pattern, and returns the smallest repeating substring. If the string does not consist of a repeating pattern, the subroutine should return undef or the empty string. e.g.:
input output 'aaaaaa' 'a' 'ababab' 'ab' 'aabaab' 'aab' 'ababaa' ''
* Difficulty: Easy

* Time: 4 minutes

Hole 4 - Hex to Char

Write a subroutine which, given a string consisting entirely of hexadecimal digits, converts pairs of digits to their ASCII character equivalents and returns the result as a list of characters. The hexadecimal digits A-F may appear in upper or lower case. There will be an even number of digits in the string. e.g.
5065726c206861636b6572 -> ('P', 'e', 'r', 'l', ' ', 'h', 'a', 'c', 'k', 'e', 'r')
* Difficulty: Easy

* Time: 4 minutes

Hole 5 - Max without Sort

Write a subroutine that accepts a list of numbers, and returns the maximum number from the list, without using Perl's built-in sort.

* Difficulty: Easy

* Time: 4 minutes

Hole 6 - Vowel Sort

Write a subroutine that accepts a list of words, and returns the list sorted by the first *vowel* that appears in each word. If two words have the same first vowel, it does not matter which is sorted first. Words will be in lowercase and will always contain at least one vowel. (Vowels are a, e, i, o, and u.)
e.g.: hole('dog', 'cat', 'fish', 'duck', 'lemur') returns: ('cat', 'lemur', 'fish', 'dog', 'duck')

* Difficulty: Easy

* Time: 5 minutes

They get harder. ;-)


In reply to PGA Golf, Round 1 by jmcnamara

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (6)
    As of 2017-09-22 11:04 GMT
    Find Nodes?
      Voting Booth?
      During the recent solar eclipse, I:

      Results (261 votes). Check out past polls.