I am trying to resolve some Ruby challenge and I have big problem with some low level (I suppose?) digits characters conversion.
Just imagine, that you need to write program, that prints on your screen sentence ex.:
"Jon Doe was born in 2017!"
using only following characters [a-zA-Z.\n ] (small & big letters, dot, space and new line)
Writing a program that prints a string using only letters, dot, space and newline might seem impossible at first, but it is actually not that hard.
Lowercase and uppercase letters allow you to invoke
Kernel methods (like
puts) as well as keywords like
true. A dot allows you to invoke methods with an explicit receiver. Space allows you to pass an argument to a method. Newline separates commands.
Let's try to get an "a":
false #=> false false.inspect #=> "false" false.inspect.chars #=> ["f", "a", "l", "s", "e"] false.inspect.chars.rotate #=> ["a", "l", "s", "e", "f"] false.inspect.chars.rotate.first #=> "a"
Now lets print "abc":
print false.inspect.chars.rotate.first print false.inspect.chars.rotate.first.succ print false.inspect.chars.rotate.first.succ.succ puts
You get the idea.
And yes, it's also possible to print spaces, punctuation and numbers using a similar approach. But I leave that to you. Take a look at the available methods and be creative.
Additional points for figuring out how to print a string without using space, just