Your skill will accomplish what the force of many cannot 

PerlMonks 
Dueling Flamingos: The Story of the Fonality Christmas Golf Challengeby eyepopslikeamosquito (Canon) 
on Jan 12, 2007 at 03:12 UTC ( #594299=perlmeditation: print w/ replies, xml )  Need Help?? 
Perl Golf is a hard and cruel game. In this report on the recent Christmas 2006 Fonality Golf Challenge, I hope to not only lay bare the secrets of the golfing masters but also tell some personal stories of triumph and despair that occurred during this fascinating competition. The Problem You must read a line of roman numerals from the standard input, for example: and write the result to the standard output: for this example. Fonality provided a more detailed and precise problem statement. A Simple Solution Here's a simple solution to the problem: This easy to understand solution hopefully makes clear some of the important strategic ideas used by the top golfers, namely:
HART: The Hospelian Arabic to Roman Transform During a Polish Golf Tournament played in March 2004, Ton Hospel rocked the Polish golf community by unleashing his miraculous magical formula to convert an arabic number to a roman numeral. I've decided to honour this magic formula with a name: HART (Hospelian Arabic to Roman Transform). This name was inspired by the ST (Schwartzian Transform) and the GRT (Advanced Sorting  GRT  Guttman Rosler Transform). Acknowledging Ton's rumoured alien origins, an alternative name is Earthman (Eyepopping Alien Roman Ton Hospelian Magical Algorithm for Numerals). If you can think of a better name, please respond away. :) As you might expect, Ton's Polish hosts were astonished by his ingenuity, Grizzley remarking: You should see some of Golfers after reading your explanation... eyes big like cups of tea, heart attacks, etc.Curiously, though he competed in this historic original Polish roman game, Grizzley did not employ HART himself in the Fonality challenge, preferring his own clever (and quite short) algorithm that was only seven strokes longer. Converting plus and minus This was an interesting little subproblem featuring the versatile tr/// (aka y///) operator. If your goal is to transform, for example, II plus III, into 2 + 3, you might dispatch the plus and minus with y/mpislun/+/d. Of course, if you cared more about jokes than strokes, you'd rearrange the letters to form y/linus.pm/ +/ instead. Which can be easily shortened, using character ranges, to y/mpaz/+/d or even y/ilz/+/d. What next? Well, if you are later using something like s/\w+/${$&}/g to convert roman numerals to arabic numbers via symbolic references, a serendipitous side effect of that s/// expression is that any lower case letters remaining in plus and minus will be eliminated! You can therefore shorten to simply y/mp/+/. As a final flourish, you can shave one further stroke by employing y/m// in harness with s/\w+/+${$&}/g. Rather than converting, for example, II plus III, into 2 + 3, the leading golfers transformed it into $II +$ III instead. If you're doing that, you can employ y/islz/$+/d to transform the plus and minus, and s''$' to prepend the leading $. An interesting alternative, attempted early in the game by Ton, is to eschew the beloved y/// operator in favour of s///, namely s'^ '+$'g and s/nus//g, though that turns out to be one stroke longer. Putting it All Together The strategy used by the top golfers in this competition is essentially a three step process:
As is often the case in golf, one insight leads to another: if symbolic references proved useful for converting one way, why not try to exploit them to convert the other way also? And, in so doing, remove the need for the @R array seen in the first simple solution above. To clarify this three step process, I've prepared a commented version with the arabic to roman numeral step abstracted into a subroutine and without any arcane golfing tricks.
Of interest here is the final line above. Remarkably, ton changed it to *_=eval, with the wry comment "More fun with globs", in only one minute twenty seconds! If Juho, who played brilliantly throughout, had found this final trick he would have tied ton for first prize. Tactical Tricks In addition to the overall strategies discussed above, tactics also play a vital role. As pointed out to me by thospel, constructing the table backwards, from 3999 down to 1, also allows you to safely place the $$$_=$_ inside the s///eg expression, since wrong entries for partial roman strings during the build get fixed later (see Ton's winning 99.56 solution below). It's also worth noting that counting downwards allows you to safely extend the range from 3999 to 4e3 thus avoiding the nasty edge case bugs that plagued the solutions of TedYoung, szeryf, Sec and Jasper, where the (invalid) 4e3 case tramples on a previously correct entry. Dueling Flamingos: The Battle of the Last TShirt Late in this game, there was a gripping duel, silently fought between two gritty characters pounding away on their keyboards in Ottawa and New York. This was the titanic Battle of the Last TShirt.
Yanick Champoux is professor of psychosexual research at the University of St Andrews The lead seesawed back and forth between `/anick Champoux and Michael Wrenn right up until the final bell, with Michael emerging the exhausted victor by a single stroke. Here is what `/anick had to say after it was all over:
And here is his final 170.51:
`/anick was the only golfer imaginative enough to employ the command line switch 040 in harness with the }{ "eskimo greeting" secret operator. I'll refrain from commenting further on his creative masterwork because, frankly, I do not understand it. Here is Michael's moving response, along with his final 169.51 solution:
Top Ten Countdown The top ten golfers at the close of play were:
In writing this report I became aware that the solutions marked with an asterisk (*) above, though they passed the referee's test program, each contained a bug, failing on one or more of the following test cases: They can all be easily remedied by changing 4e3 to 3999, at the cost of a single stroke. Since I'm sure each of these golfers would have found this trivial fix had the referee's test program been more exhaustive, I've taken the liberty of adjusting their scores above and their solutions below. Please note that I am not the tournament referee and therefore do not have any authority to make a decision on this matter. I bring it to light here only in the interests of historical accuracy. It is interesting to note that nine of the top 10 had previously competed in the strenuous TPR tournament circuit of 2002. And the only one who hadn't, jojo, had played 12 challenges previously at codegolf. 10. Util (129.50) Util has limited previous golfing experience, having competed in two tournaments in the 2002 TPR season, finishing the season in 121st place, with winnings of $59,000. Accordingly, I expect he was well satisfied with a top ten finish.
Though some strokes can be whittled from this lookup hash approach  for example, this one: is 12 strokes less fat  Util really needed to find the symbolic reference hack to join the leading pack. 9. Jasper (126.46) Jasper is a very experienced golfer, having competed in ten tournaments in the 2002 TPR season, finishing the season in 13th place, with winnings of $719,600. Jasper was the highest placed of those golfers who missed Ton's magic roman formula.
What was astonishing here is that Jasper had never heard of mtve's book of golf containing Ton's magic roman formula. This is despite playing in many, many golfs over the years and being mentioned many times in the book himself. 8. eyepopslikeamosquito (122.54)
eyepopslikeamosquito is an experienced golfer, having competed in eight tournaments in the 2002 TPR season, finishing the season in 17th place, with winnings of $652,400.
Like Util, eyepopslikeamosquito wasn't really in the game because he failed to find the symbolic reference trick. While Util used a hash lookup, eyepopslikeamosquito tried grep in harness with a sub. 7. Sec (120.51) Sec is an experienced golfer, having competed in eight tournaments in the 2002 TPR season, finishing the season in 57th place, with winnings of $179,467.
Of note here, is that Sec only spent half a day on the entire tournament. Impressive. 6. pijll (118.53) pijll is a champion golfer, having competed in ten tournaments in the 2002 TPR season, finishing the season in 3rd place, with winnings of $3,540,000. Notably, pijll has beaten ton in headtohead matches on at least three occasions, winning the tournament each time.
pijll is such a classy golfer that had you mentioned in passing, "Erm, (ugene, why not try using a symbolic reference in this game?", I have no doubt that pijll would have been battling with ton and Juho for first prize a few hours later. 5. szeryf (115.52) szeryf is an experienced golfer, having competed in one tournament in the 2002 TPR season, finishing the season in 123rd place, with winnings of $56,000. In his only tournament in that season, he thrillingly came from behind to snatch the Beginner's trophy. Since then he has competed in a number of Polish golf tournaments.
4. jojo (111.49) jojo is a mystery golfer. If anyone knows more about him/her, please let us know. jojo is an experienced golfer, having competed in 12 challenges at codegolf where he/she is currently in 15th place overall.
3. TedYoung (108.53) TedYoung is an experienced golfer, having competed in three tournaments in the 2002 TPR season (under the moniker Theodore Young), finishing the season in 82nd place, with winnings of $127,200.
TedYoung was the surprise packet of the tournament. He has clearly moved to a higher golfing plane since 2002. 2. Juho Snellman (102.54) Juho Snellman is a brilliant golfer, having competed in six tournaments in the 2002 TPR season finishing the season in 6th place, with winnings of $1,264,000.
Juho put in a really gutsy performance, gallantly leading the pack relentlessly pursuing ton during the last days. Indeed, only failing to unearth ton's little *_=eval "More fun with globs" trick prevented Juho from sharing first place in this competition. 1. ton (99.56) ton (aka thospel) is a legendary golfer, having competed in ten tournaments in the 2002 TPR season finishing the season in 1st place, with winnings of $4,384,000 ($4,384,350 now ;).
In addition to breaking the magic 100 barrier, ton managed to concoct the first known functional smiley in a golf winner's solution. (: Since ton invented the magic formula in the first place, I feel he was a most worthy winner. Congratulations thospel! References
Acknowledgements: I'd like to thank cog for writing the Acme::AsciiArt2HtmlTable module, which was used to generate the little pictures above. I'd also like to thank Samy Kamkar of LA.pm for refereeing the Fonality tournament on his own. Update: I seem to have hit the size limit of a meditation, anyway the last bit got chopped off, so I had to remove the little orange picture of pijll to get it to fit. :( Update: Added new "Tactical Tricks" section (thanks thospel) and expanded "Top Ten Countdown" section a bit.
Back to
Meditations

