The three rules of Ruby Q. 2:
Please do not post any solutions or spoiler discussion for this
quiz until 48 hours have passed from the time on this message.
Support Ruby Q. 2 by submitting ideas as often as you can! (A
permanent, new website is in the works for Ruby Q. 2. Until then,
please visit the temporary website at
Suggestion: A [QUIZ] in the subject of emails about the problem
helps everyone on Ruby T. follow the discussion. Please reply to
the original quiz message, if you can.
Your task this week is to count. Yup, that’s it.
Oh, by the way… You may only use the characters
Specifically, define a function
symbolify that accepts an integer
and returns a string composed of only the five characters shown above.
The string, when evaluated, will equal the original number passed in.
That is, the following test code should raise no exceptions:
1000.times do |i| s = symbolify(i) raise "Not a string!" unless s.is_a? String raise "Invalid chars!" unless s.delete("?*()-").empty? x = eval(s) raise "Decode failed!" unless i == x end
There are at least a few different approaches that come to mind, so
don’t expect everyone to have the same output. Well, not before the
output is passed through
eval, that is.
I am not requiring that you produce the shortest string (though you
are welcome to attempt such a thing). The only thing I do ask is
that you not produce megabytes of data to represent a simple integer.
P.S. Cheating is encouraged (except that you may not write code