Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Compression in Golf: Part III

by Anonymous Monk
on Mar 30, 2013 at 15:53 UTC ( #1026287=note: print w/replies, xml ) Need Help??

in reply to Compression in Golf: Part III

This is my 151 stroke solution.

My strategy was trying to compress your 160 without sacrificing strokes to pack's constraints (escaping G and T took 4):

eval lc(j x 165^pack$<^C,'(M\xe2(\x9d\xe2\x86\x1b\x9b\x98\x81^xc\xe4\xa1\x9a\x12*y\x852b\x0f=\x88\xe6\x14I\x9e\x08\xf9\x9d,a\xa3\x99\x99eY\xf7\x8b\x04\xfa\x85\x10\xfa\x8e\x15\xd1*,C\xaah\xb6Y\xa87\xaa-\x81_\x10\xe9\xaa(I\x00\x00\xa1&\xa8\xa2d\x02W\xc4x1\xa5\x92L\xf3\x92\x00!\x97\x16\x98\x0cG\xa8\xba\xd5\x9f4Z\x9e\x16\xa7\x82>\xa6^\x15\x83\xea,C\xaa!\xf4\xeadQ\xcf\xa8qX>\xeb(')

So, after discovering Perl string bitwise operators, I applied ToastyX's law of PHP golf to Perl.

With the right timing x 165 can be replaced by x$$, saving two strokes.



Replies are listed 'Best First'.
Re^2: Compression in Golf: Part III
by eyepopslikeamosquito (Bishop) on Mar 31, 2013 at 13:27 UTC

    To help the casual reader appreciate the depths of depravity and deviousness of dmd's solution, consider this snippet:

    j x 165^pack$<^C,'packed-string'
    For this to work:
    1. Perl must interpret $< (aka $UID) as a string, not a number, otherwise the xor with "C" will not produce the desired "u" for pack's first parameter.
    2. The $< special variable must be greater than or equal to 1123 because 123 is the length of the compressed string. This special variable seems to take the value 65534 on the codegolf server, so the string produced by $<^C there is "u5534".
    3. dmd was undeterred by "u5534" being way out of range for pack. On the contrary, this turned out to be an opportunity because perl 5.8 has a nasty memory bug (fixed in later perl versions, as mentioned in Compression in Golf: Part I) so that going beyond "u63" essentially results in a random value for the length byte, depending on what happens to be in the memory being read beyond the end of the PL_uudmap[] array. That is, this solution works with the perl 5.8.8 running on the codegolf server but fails with later perl versions and may even fail with perl 5.8 running in a different environment.
    4. The random value dmd got in the first position as pack's length byte on the codegolf server happened to be "f" which he was able to exploit by xor'ing with "j" to produce form-feed (ord 12) as the leading character, so as not to muck up the program string to be eval'ed (as a leading "f" would have done). By the way, if you could somehow fluke a leading "s" or "@" for the length byte you may be able to shave another stroke because short solutions to the bottle golf typically start with "s" or "@".
    That is, like many winning codegolf solutions, this one hangs by a thread.

    With the right timing x 165 can be replaced by x$$, saving two strokes
    Now that's just sick. If you managed to submit your entry at just the right time when $$ took the value 165 on the codegolf server, I salute you! This reminds me of some of the antics described in the "Outsmarting the Robot Referee" section at The golf course looks great, my swing feels good, I like my chances (Part IV) where entries were submitted when the $^T time variable took just the right value on the codegolf server.

    Thanks for sharing your solution. I find it hilarious that when we were tied for the lead at 151 strokes, we both probably assumed we had similar solutions, when, in fact, they were completely different. :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026287]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2021-04-19 00:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found