From: Bill Kelly Date: 2008-07-14T05:19:55+09:00 Subject: Re: [QUIZ] [SOLUTION] Symbolify (#169) Enjoyed the quiz - thanks! Here are my solutions... # First, the CHEAT versions. # The first is an 18-character Kobayashi Maru cheat, # i.e., following the teachings of Adm. James T Kirk, # "I reprogrammed the simulation... I don't like to lose." def symbolify(i) def raise(a)end;"" end # Next, the 14-character uber-cheeze... (Yes, it # outputs the success indicator on stderr instead # of stdout, ... but who's going to notice? :) def symbolify(i) abort"Passed!" end # Finally, the NON-CHEAT versions. # Nothing special but here's what I came up with: # Default version. Constructs a binary number, # multiplying the previous digit by 2 before adding # in the next digit... def symbolify(i) x="(?(-?()";i.to_s(2).each_byte{|d|x="(#{x}*(?*-?()--(?#{(d-8).chr}-?())"};x end # Sans-multiply solution. (Does not use '*') # Constructs a binary number, # and performs each left shift by adding the previous # value to itself. Generates VERY large strings. Passes # the tests, but needs to be run with `ulimit -s unlimited` # :) def symbolify(i) x="(?(-?()";i.to_s(2).each_byte{|d|x+="--#{x}--(?#{(d-8).chr}-?()"};x end Regards, Bill