|
|
| Pathologically Eclectic Rubbish Lister | |
| PerlMonks |
Comment on |
| ( #3333=superdoc: print w/ replies, xml ) | Need Help?? |
|
In golf, there are many more failed attempts than successful breakthroughs. That's the nature of the game. To keep the articles reasonably short, I focused on the breakthroughs, omitting many of the failures. To add a dose of reality, and while I'm still able to remember, I thought I'd describe some of my more interesting "heroic failures" in this game. You never know, someone may find an improvement and transform one of these failures into a winner. Mapping to Different Number Bases Mapping to different number bases is a generally useful golfing technique. While I couldn't find a useful number base mapping for the original M -> 1000, D -> 500, C -> 100, L -> 50, X -> 10, V -> 5, I -> 1, I spied an opportunity later in the game after uncovering the alternative M -> 2000, D -> 1000, C -> 200, L -> 100, X -> 20, V -> 10, I -> 2 mapping, illustrated in the following table.
Noticing this cute mapping led directly to the following Python 82 stroker: As you can see, this solution was not competitive in this game only because of the five stroke Python string to int conversion penalty of having to call int() -- which wouldn't have been required in Perl or PHP. This idea was similarly foiled in Ruby by the need for string to int conversion. Equally cruelly, in a language where the string to int conversion is not required, namely PHP, this idea was crushed by the arbitrariness of PHP's internal function names. You see, PHP calls this function not oct, like any reasonable language, but decoct, costing three precious strokes. Aaargh. Finally, in Perl, the oct function converts the other way and I couldn't find any very short way to convert from decimal to octal. Eliminating Exponentiation Though exponentiation is "natural" for Roman numerals, it does cost around six strokes (10**()), leaving the door open for shorter, if less natural, alternatives -- such as the PHP md5 lucky hit found in the third article of this series. Though less ideal than PHP's md5 function, Python's built-in hash function seems the best hope of eliminating exponentiation among the other three languages. Indeed, this 79 stroker proved only one stroke too long: This formula should be able to be further shortened with a more direct mapping of a longer magic string, such as: Though such a solution should exist -- just like the "proven" shorter PHP md5 solutions -- I was unable to write a fast enough search program to find one. In reply to Re: The golf course looks great, my swing feels good, I like my chances (Part II)
by eyepopslikeamosquito
|
|