### Re: Dueling Flamingos: The Story of the Fonality Christmas Golf Challenge

by primo (Scribe)
 on Dec 17, 2012 at 08:52 UTC ( #1009126=note: print w/replies, xml ) Need Help??

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

Replies are listed 'Best First'.
Re^2: Dueling Flamingos: The Story of the Fonality Christmas Golf Challenge
by eyepopslikeamosquito (Bishop) on Dec 17, 2012 at 11:52 UTC

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!

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!
In addition to the one used in the 2006 Fonality golf challenge:
```s!.!y\$IVCXL426(-:\$XLMCDIVX\$dfor\$\$_.=5x\$&*8%29628
don't forget about Ton's original one of equal length:
```s!.!y\$IVCXL91-80\$XLMCDXVIII\$dfor\$\$_.=4x\$&%1859^7
used in the 2004 Polish golf tournament.

Update: Here is a test program to verify that all four magic formulae are correct:

```use strict;
use Roman;

sub ton1 { my \$t = shift; my \$s;
(\$s.=4x\$_%1859^7)=~y/IVCXL91-80/XLMCDXVIII/d
for \$t=~/./g; return \$s }

sub ton2 { my \$t = shift; my \$s;
(\$s.=5x\$_*8%29628)=~y/IVCXL426(-:/XLMCDIVX/d
for \$t=~/./g; return \$s }

sub pmo1 { my \$t = shift; my \$s;
(\$s.="32e\$_"%72726)=~y/CLXVI60-9/MDCLXVIX/d
for \$t=~/./g; return \$s }

sub pmo2 { my \$t = shift; my \$s;
(\$s.="57e\$_"%474976)=~y/CLXVI0-9/MDCLXIXV/d
for \$t=~/./g; return \$s }

for my \$i (1..3999) {
my \$r  = uc roman(\$i);
my \$t1 = ton1(\$i);
my \$t2 = ton2(\$i);
my \$p1 = pmo1(\$i);
my \$p2 = pmo2(\$i);
print "\$i: \$r\n";
\$r eq \$t1 or die "t1: expected '\$r' got '\$t1'\n";
\$r eq \$t2 or die "t2: expected '\$r' got '\$t2'\n";
\$r eq \$p1 or die "p1: expected '\$r' got '\$p1'\n";
\$r eq \$p2 or die "p2: expected '\$r' got '\$p2'\n";
}
print "all tests successful\n";

Create A New User
Node Status?
node history
Node Type: note [id://1009126]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2021-04-19 15:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?