Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Dueling Flamingos: The Story of the Fonality Christmas Golf Challenge

by eyepopslikeamosquito (Canon)
on Jan 12, 2007 at 03:12 UTC ( #594299=perlmeditation: print w/ replies, xml ) Need Help??

Any problem in computer science can be solved with another layer of indirection.

-- David Wheeler

Whee, $$$_=$_

-- Juho Snellman celebrates finding that extra layer during the Fonality Golf Challenge

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:

II plus III minus I
and write the result to the standard output:

IV
for this example. Fonality provided a more detailed and precise problem statement.

A Simple Solution

Here's a simple solution to the problem:

#!perl -lp map{$_.=(!y/IVXLC/XLCDM/,I,II,III,IV,V,VI,VII,VIII,IX)[$&]while s/\d// +;$$_=$n++}@R=0..3999; y/mp/-+/;s/\w+/${$&}/g;$_=$R[eval]
This easy to understand solution hopefully makes clear some of the important strategic ideas used by the top golfers, namely:
  • Rather than attempting to calculate a running total, $_ is transformed in place. For example, II plus III is transformed into 2 + 3. With that done, eval is employed to compute the total.
  • The y/IVXLC/XLCDM/ transliteration is a short and sneaky way to multiply by ten.
  • You don't need to write two converters: it is sufficient to write an arabic_to_roman() converter. To convert the other way, simply convert 1..3999 into a table or something and do a lookup.
  • It turns out that symbolic references are crucial in this game because they are shorter than other lookup techniques, such as hashes. In the simple solution above, a symbolic reference is created for each roman numeral whose value is the corresponding arabic number.

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 (Eye-popping 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 sub-problem 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/mpa-z/-+/d or even y/il-z/-+/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/isl-z/-$+/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:

  1. Convert, for example, II plus III, into $II +$  III.
  2. Build two sets of symbolic references: one mapping roman numerals to their corresponding arabic number, the other mapping (negative) numbers back to the roman numerals. Notice that you must use negative numbers because positive ones (e.g. $3) are read-only variables used by perl's regex engine. The building of this second set is easily recognized by the surreal construct: $$$_=$_.
  3. Eval the expression built in step one and put the result back into $_ for printing, courtesy of the -p option.

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.

#!perl -lp # r() converts an arabic number (1..3999 or -3999..-1) to a roman nume +ral # using a non-destructive variation of Ton's magic formula (HART). sub r{my$s;($s.=5x$_*8%29628)=~y$IVCXL426(-:$XLMCDIVX$dfor/./g;$s} y/iul-z/-$+/d; # Step 1: convert plus and minus to +$ +and -$ s''$'; # Step 1: prepend $ $$_=r(),$$$_=$_ for-3999..-1; # Step 2: build two sets of symbolic re +ferences $_=${+eval}; # Step 3: eval the expression

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 T-Shirt

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

Yanick Champoux is professor of psycho-sexual research at the University of St Andrews

The lead see-sawed 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:

But nevermind that blunderific overlook of the Great Thome of Golfic Knowledge. Nevermind an obscenely tumefied forehead, caused by repeated percussions against my desk during the ever-excruciating quest for the next shaved stroke. What really make me wail like a tax-audited banshee is that the referee just went through the last of the pending entries, allowing m.wrenn to sneak one stroke ahead of me and bump me off the top 20, literally yanking the prized t-shirt off my clenched fists.

m.wrenn, if you are on this list, consider my fist -- yes, that same fist that you so fiendishly robbed from its prize -- shaked in barely suppressed fury in your general direction. And mark my words: one day, I shall have my revenge upon thee!

And here is his final 170.51:

#!perl -lp040 $s=/m/ if/u/;($y=I1V5X10L50C100D500M1000IV4IX9XL40XC90CD400CM900)=~/$&/,$i=$t ++=$s^"$;">($;=$')?-$;:$;while s/.$//}{1while$y=~/(\D+)$i/&&$t>=$i?($_.=$1,$t-=$i):$i--

`/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:

I went out to get some dinner and returned to check on my solid 20th Place (securing a prized Fonality/trixbox T-shirt) ... when what to my wondering eyes should appear, but \'anick the Canuck who was now TWO STROKES CLEAR! I CURSEd and I SHOUTed and I called him some names| That Bastr/a//d! That foo|bird! That Flamingo again!!! I'll catch him! I'll pass him! I'll beat him this time! I'll punk him! I'll twizzle and addle his brain! To the top of the board! Past Juho and ton! Now slash away, slash away, slash away all!

When I came to, I was still one stroke back and all my hair had been yanked out and deposited on the floor next to me. That \'akinc! It was after 1AM and I needed inspiration. I went into my closet and tried on all of my T-shirts ... None of them fit! I needed a NEW one!

So, I had another beer (a nice Belgian one) and kept at it and just before 2AM, I saw the light! An extremely obvious 2 stroker that I had tried earlier in a slightly different form. I could feel that feeling of cotton ...

#!perl -lp @@{@@=map{$_,$_.0,$_*100}4,5,9,10}=qw(IV XL CD V L D IX XC CM X C M);f +or$~(@@){s/$@{$~}/"I "x$~/ge}s/I//while s/m\w* +I/m /;$~=y/I//cd;s/I{ +$~}/$@{$~}||$&/gewhile$~--

Top Ten Countdown

The top ten golfers at the close of play were:

PlaceScorePlayerCountry
199.56tonNetherlands
2102.54Juho SnellmanFinland
3108.53*TedYoungUSA
4111.49jojoFrance?
5115.52*szeryfPoland
6118.53pijllNetherlands
7120.51*SecGermany
8122.54eyepopslikeamosquitoAustralia
9126.46*JasperUK
10129.50UtilUSA

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:

{ in => "MD plus I\n", out => 'MDI' . "\n" }, { in => "MD minus I\n", out => 'MCDXCIX' . "\n" },
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.

#!perl -lp $==$_,s!.!y$IVCXL91-I0$XLMCDXVIII$dfor$_[$=].=4x$&%1859^7;5!egfor+0..3 +999;@&{@_}=0..@_;y/il-z/-+/d;s/\w+/$&{$&}/g;$_=$_[eval]

Though some strokes can be whittled from this lookup hash approach -- for example, this one:

#!perl -lp s!.!y$IVCXL91-I0$XLMCDXVIII$dfor$X[$_].=4x$&%1859^7!egfor+0..3999;@Y{@ +X}=0..@X;y/m/-/;s/\w+/+$Y{$&}/g;$_=$X[eval]
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.

#!perl -lp map{y/IVXLC/XLCDM/,s!\d!$&^4?$&^9?V x($&>3).I x($&%5):IX:IV!ewhile//;$ +$_=$n++}@d=0..3999;y/m/-/;s/\w+/+${$&}/g;$_=$d[eval]

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.

#!perl -lp sub'_{$;=0;($;.=5x$_*8%29628)=~y$IVCXL426.-X$XLMCDIVX$dfor/./g;$;}y;mp +;-+;;s>\w+>(grep$&eq&_,1..1e4)[0]>eg;$_=_$_=eval

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.

#!perl -lp @%=map{my$a;s/./y!IVCXL91-80!XLMCDXVIII!dfor$a.=4x$&%1859^7/eg;$$a=$/- +-;$a}0..3999;y/i/-/;s/\w+/${$&}/g;$_=$%[-eval]

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 head-to-head matches on at least three occasions, winning the tournament each time.

#!perl -pl y/i-z/-+/s;for$a(1..4e3){$a=~s#.#($n[$a].=4x$&%1859^7)=~y$IVCXL91-I0$X +LMCDXVIII$d;s/\b$n[$a]\b/$a/g#ge}$_=$n[eval]

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.

#!perl -pl @;=map{$a=0;($a.=4x$_%1859^7)=~y!IVCXL91-80!XLMCDXVIII!dfor/./g;$$a=$_ +;$a}s''$'>y/isl-{/-$+ /..3999;$_=$;[eval]

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.

#!perl -pl s|.|y;CLXVI624.-=;MDCLXXVI;dfor$$_.=5x$&*8%29628;$&|ge,$$$_=$_^Kfor-4e +3..o;s;\w+;${$&}|$&&'-';ge;$_=${+eval}

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.

#!perl -lp y,iul-~,-$+,d,$_=eval,${$@}=1..!s/./y@IVCXL91-:0@XLMCDXVIII@dfor$@.=4x +$&%1859^7/egfor$...3999,u.$_;$_=$@

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.

#!perl -pl $_=${s!.!y$XLIVC246,-:$CDXLMVIX$dfor$$_.=8x$&*5%29628;$$$_=$_!gefor-4e +3..s''$'/y/isl-~/-$+/d;eval}

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

#!perl -pl s!.!y$IVCXL426(-:$XLMCDIVX$dfor$$_.=5x$&*8%29628;$$$_=$_!egfor-4e3..y/ +iul-}/-$+ /%s''$';*_=eval

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.

Comment on Dueling Flamingos: The Story of the Fonality Christmas Golf Challenge
Select or Download Code
Re: Dueling Flamingos: The Story of the Fonality Christmas Golf Challenge
by dewey (Pilgrim) on Jan 12, 2007 at 10:46 UTC
    Man, golf continues to blow my mind... thanks for taking the time to write this up, much easier to understand the solutions now.
    ~dewey
Re: Dueling Flamingos: The Story of the Fonality Christmas Golf Challenge
by eyepopslikeamosquito (Canon) on Jan 15, 2007 at 09:04 UTC

    Just a couple of updates from the post mortem at golf@perl.org.

    It's surprisingly easy, when "golfing fatigue" sets in towards the end of a long and gruelling tournament, to resemble Mr Magoo.

    So it proved here in the gripping Battle of the Last T-Shirt, where `/anick might have grasped the precious last shirt, simply by changing =~/$&/ to =~$&. Of course, m.wrenn may well then have thrillingly re-snatched the prized garment with the routine transform of:

    qw(IV XL CD V L D IX XC CM X C M)
    to:
    (IV,XL,CD,V,L,D,IX,XC,CM,X,C,M)

    With the recent completion of PPI and Perl::Critic, it should now be feasible to write a module that detects and prevents many common golfic oversights, such as the two cited above. You might implement this as a collection of Perl::Critic policies. A more sophisticated Games::Golf::MrMagoo module might even automatically try each possible shortening against the test program and only report those that pass.

    Oh, and Util's hash-based approach has now been whittled from 129.50 all the way down to 114.47:

    #!perl -pl @%{@;}=0..map+s!.!y$IVCXL426(-:$XLMCDIVX$dfor$;[$_].=5x$&*8%29628!eg,! +y/m/-/..3999;s/\w+/+$%{$&}/g;$_=$;[eval]
    So it seems that hashes are clearly the second best lookup technique after symbolic references.

Re: Dueling Flamingos: The Story of the Fonality Christmas Golf Challenge
by diotalevi (Canon) on Jan 15, 2007 at 15:14 UTC

    What do flamingos have to do with this?

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

      What do flamingos have to do with this?
      The two "dueling flamingos" in this competition were the two battling for the last T-shirt, namely `/anick Champoux and Michael Wrenn. I was looking for a lively title for this article and got the idea from Michael's comment, quoted in the article, which was made in response to `/anick overtaking him on the leaderboard yet again:
      I went out to get some dinner and returned to check on my solid 20th Place (securing a prized Fonality/trixbox T-shirt) ... when what to my wondering eyes should appear, but \'anick the Canuck who was now TWO STROKES CLEAR! I CURSEd and I SHOUTed and I called him some names| That Bastr/a//d! That foo|bird! That Flamingo again!!! I'll catch him! I'll pass him! I'll beat him this time! I'll punk him! I'll twizzle and addle his brain!
      I guess it's hard to relate to these emotions unless you've actually played in one of these competitions and experienced first hand the bizarre experience of finding yourself cursing and swearing at total strangers from all over the world for passing you on the leaderboard. :-)

        I had to give up golfing after a few shots at http://codegolf.com for lack of time (and/or sleep, you choose), but two things I will remember forever: how totally compulsive all this stuff can become, and how wild you can become when you either curse someone for passing you, or you pass them again giving them what they deserve!

        Flavio
        perl -ple'$_=reverse' <<<ti.xittelop@oivalf

        Don't fool yourself.
Re: Dueling Flamingos: The Story of the Fonality Christmas Golf Challenge
by ambrus (Abbot) on May 10, 2009 at 10:22 UTC

      I happen to have an old text file copy of the post mortem lying around on my local hard disk. Better upload it here for safe keeping before I have a hard disk crash. :) Actually, the whole post mortem is too big for a Perl Monks node, so I've just uploaded all of the post mortem up to 200 strokes.

Re: Dueling Flamingos: The Story of the Fonality Christmas Golf Challenge
by primo (Beadle) on Dec 17, 2012 at 08:52 UTC

    I've managed to reduce the Hospelian Arabic to Roman Transform by one byte.

    As a lead-in, I've read most of your nodes at some point (always good reading, btw), and when I first saw Ton's amazing formula, I spent a few moments dissecting it to figure out how it did what it did. Recently, while working on a similar problem, I decided to see if I could reproduce his formula, armed with the knowledge of how it worked.

    A few hours of brute forcing later, and I had a result. Naturally, I wanted to check back here to see how I had done. I was pleasantly surprised to find that I had stumbled upon a formula that was one byte shorter!

    Ton's original formula:
    y/CLXVI6240-9/MDCLXXVI/dfor$$_.=5x$&*8%29628

    The one byte improvement:
    y/CLXVI60-9/MDCLXVIX/dfor$$_.="32e$&"%72726

    Alternative:
    y/CLXVI0-9/MDCLXIXV/dfor$$_.="57e$&"%474976

    Even though "32e$&"%72726 is one byte longer than Ton's 5x$&*8%29628, it saves 2 bytes in the transliteration, because 01 is transliterated with IX. The alternative transliterates 012 with IXV, saving yet another byte, but it uses a modulus that's one digit longer.

    Update:
    Since originally posting, I've found several more alternatives of the same length, using multiple substitutions for I and/or V:

    y/CLXVI0-9/MDCLXIVXI/dfor$$_.="49e$&"%87971 y/CLXVI0-9/MDCLXIIXIV/dfor$$_.="7e$&"%10606 # y/CLXVI0-9/MDCLXIIXIV/dfor$$_.="7e$&"%15909 # y/CLXVI0-9/MDCLXIIXIV/dfor$$_.="7e$&"%31818 # These are all essential +ly the same y/CLXVI0-9/MDCLXIIX V/dfor$$_.="8e$&"%61535 # Doesn't contain 3 anywh +ere # although this is one byte longer, it saved a byte in the challenge I + was working on y/CLXVI60-9/MDCLXXI V/dfor$$_.="37e$&"%97366 # Doesn't contain 1 anywh +ere

      I've managed to reduce the Hospelian Arabic to Roman Transform by one byte
      You can't just say that so casually! This is the legend, Ton "the alien" Hospel we are talking about, the greatest golfer of his generation!

      Peering at your new "32e$&"%72726 concoction brings fond memories flooding back, reminding me of a short Perl roman-to-decimal magic formula ("1E@-"%9995) and some similar ones I stumbled on in PHP (e.g. "5E$c"*1%4999) all those years ago. Of all the aspects of golf, I find magic formulae the most fascinating.

      Though retired from golf nowadays, thospel and mtve occasionally visit here, so I'll attempt to contact them, in case they wish to comment on your brilliant new formula. Oh, and you might be interested in this Jan 2007 email thread where ton ponders how his winning score in this game might be beaten.

      I have long admired your many and varied golfing exploits: leading 1000 digits of pi in all four languages (Perl, Python, Ruby, PHP) ... then soundly defeating the hitherto unbeatable PHP golfing maestro ToastyX ... and now this. I stand humbled, Great Primo.

      Update: primo's improvement demonstrates that, instead of whining, it was possible to beat Ton in this game, as thospel pointed out at the time:

      No actually. There was a second way of winning: make up your own secret. Nothing stops anyone from thinking of the magic formula for himself. It's also perfectly possible there is an even better way to go from number to roman that nobody discovered yet.

        It's unfortunate that those golfers did feel so very disadvantaged about not being 'in the know' about Ton's discovery. But I have to agree with Ton's words on this:

        Nothing stops anyone from thinking of the magic formula for himself.

        At this point, it might be worth mentioning that there are vastly many Ton-length or near-Ton-length formulae, waiting to be had by anyone who had thought to look for one. My (poorly written) brute forcer found several almost immediately:

        "12e$&"%109082 # I=0, V=[89], X=[347] "12e$&"%109083 # I=0, V=7, X=[649] "12e$&"%109086 # I=0, V=4, X=[35] "14e$&"%87498 # I=0, V=2, X=6 ...

        the last of which is equal in length to Ton's. Of course, the most difficult part of finding a magic formula is not writing the search algorithm, but knowing what to search for in the first place. Given that you know that you will be transliterating digits for numerals (admittedly, a logical step that I was spared), a few things should be immediately apparent:

        1. The base of the expression should increase by a factor of 10 for each digit. This follows directly from the regularity (the adding of one digit) expressed from 0-3, and again from 5-8 (Ton's expression increases by a factor of 10 plus a constant, but the result is similar).
        2. The modulo should fall between the value for 3, and the value for 4. This follows directly from the fact that 4 breaks the above mentioned regularity.
        3. The value for 5, after the modulo, should be smaller than the modulo/1000. This follows directly from the fact that the regularity beginning with 5 needs to continue until 8.

        The most obvious formulation of this is "XXe$&"%YYYYYY. Had none of these worked (instead of the vastly many that do), I'm not sure if I would have thought of string repetition as a suitable candidate as Ton did, but probably not. At least, not in any short period of time.

        As an aside, there are no other solutions of the form that Ton used (1x$&*XX where Ton's XX is 40). It seems that his solution truly is a one of a kind!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://594299]
Approved by GrandFather
Front-paged by McDarren
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2014-08-29 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (289 votes), past polls