Find all the anagrams in a given input stream and display them in the specified format.
An anagram is a word (or phrase, but we'll stick with words for this
contest) formed by rearranging the letters of another word (or phrase). For
The program is a filter: it must read from STDIN, and send output to STDOUT.
The input file is a text file of words, one word per line. Each word consists of [a-z] only.
Each input line consists of the word only, with no leading or trailing whitespace, and no empty lines (unless the file is empty).
All input lines are properly newline terminated, and do not contain binary 0.
All input files have a total size so that they will fit comfortably in memory and still allow you ample memory to play with. Please note that the input file can be empty.
You may assume ASCII as the character set but you may not use Unicode-specific semantics.
You may not assume that input file will be sorted.
You are to print the anagrams found, one line for each set.
You are to print the anagrams and only the anagrams: you are to discard standalone words with no anagrams.
A line of output consists of all the words that anagrams the others: each word is separated by one space (no leading/trailing space allowed).
Each set of anagrams will not exceed 15 words per anagram.
The words on each output line will be sorted alphabetically.
The output lines are first sorted by number of words (the fewer first), then alphabetically using the first word of the line (after the line itself is sorted alphabetically).
All output lines must be properly newline terminated.
You must not write to STDERR.
The program return code does not matter.
The average runtime of the program must be finite, but may be arbitrarily long.
The program can be written as one or more lines. The score is the total
number of characters you need (smaller is better). If your program is more
than one line, you must count the newlines in between as one character
each. The #! line is not counted. If you use options on the #! line, the
options themselves are counted, including the leading space and
If two (or more) identical solutions are submitted, there is a tie. For solutions that have the same score with different characters, this month's tiebreaker favors the solution with the smallest number of different characters.
For instance, this solution:
$ab = $cd * $ef
would lose to this solution:
$ab = $ad * $afUpdate: The tie-breaker algorithm does not take into account literal newlines.
All programs must work on perl 5.6.1 (most likely programs you write on another version will be just fine, so don't directly go downloading a different perl).
Assume total memory is < 2**32 bytes (this implies sizes of arbitrary datastructures can be represented as a plain integer, and that you must not try to generate arbitrarily big datastructures).
The program may only use the perl executable, no other executables on the
system are allowed (the program may use itself though). You may use any of
the perl 5.6.1 standard core modules (
for a list of those core modules). Your solution must be portable in the
sense that it should work on all versions of 5.6.1 everywhere (however,
it's perfectly fine to abuse perl 5.6.1 bugs).
When tested, your script will be named anagrams.pl, and you must assume your script to have file permissions of 0644 (ie, non-executable for windows folks).
Given the input:
hack snooped tables salt spiff feeling spooned last grep bleats gas ablest fleeing stable slat drive
You are to output the following:
feeling fleeing snooped spooned last salt slat ablest bleats stable tables
The game starts April 1st (00:00 UTC) and ends April 8th (00:00 UTC).
A test program is provided to help screen entries.
Any program that passes the test program should be submitted. If you are surprised that your solution passed the test program, please submit it anyway! That will help us identify bugs in the test program.
For the test program to work correctly, you will have to name your script anagrams.pl and place it in the same directory as your test program. Run the test program:
$ perl tpr02.pl
to verify that your entry is valid.
Passing the test program does not assure your solution is valid. The referees have the final say.
You can submit your solution here (you'll notice it's the same page as the Leaderboard).
Do not publish your solutions anywhere. That will spoil the game, as your solutions are meant to be secret. All solutions will be published at the end of the game.
Prizes (provided by The Perl Review) will be awarded to veteran and beginner winners. A prize may also be awarded to any especially interesting artistic and/or unorthodox solutions.
You can track your ranking through the leaderboard here. Beginners are encouraged to enter and there is a separate leaderboard for them.
We encourage you to send feedback as well as your ideas for future holes and tiebreakers to firstname.lastname@example.org.
As Perl Golf grows in popularity, the number of solutions submitted threatens to overwhelm the referees. We would like to thank Peter for accepting our invitation to join the ranks of Golf Referees. In order to allow Peter (and maybe even Jérôme and Dave) to play in future golf challenges, we would like to create a ``pool of referees''. For each tournament, the necessary amount of referees would be used. Referees in the pool do not have to referee every month.
If you'd like to be a part-time referee, drop us a note: email@example.com