This is not required extra work... just for a little more fun. I have
some suspicions about some techniques, what I call "ugly" cheats (as
opposed to the "pretty" cheats who ignored you in high school... umm,
ignore that last part).
Anyway, here's another test:
nums = (0...1000).sort_by { rand }
strs = nums.map { |n| symbolify(n) }
strs.zip(nums).sort_by { rand }.each do |str, num|
res = eval(str)
raise "Not a string!" unless str.is_a? String
raise "Invalid chars!" unless str.delete("?*()-").empty?
raise "Decode failed!" unless res == num
end
puts "Passed!"
This might affect some, maybe not others. I wrote two solutions, one
classified as "pretty" while the other is "ugly" (i.e. fails this
test). Again, you're not required to pass this... Looking at some ugly
solutions will certainly be okay.
Interestingly, my pretty solution confuses IRB. If I run on the
command line:
> ruby -r moss test.rb
Passed!
However, if I start up irb:
> require 'moss'
=> true
> symbolify(60)
Then I get a nice stack crawl (not gonna show yet, spoiler) that ends
in "Maybe IRB bug!!!". (I imagine you guys can guess what I'm
doing...)