Having completed a number of certification exams I am finally getting back to what I love learning languages. I had been working on the python challenge while learning python, but that was some time ago. I think I was up to level 10, but it has been a several months, so I decided to start back at the beginning and to try ruby. The 1st challenge (after the warm up) is to decode a short bit of text using this key;
Obviously they want you to increment the letters forward two characters.
I struggled along for a few hours, skimming through a couple of tutorials on ruby, and finally came up with this;
#!/usr/bin/ruby #garbage="g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. \ bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle \ qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj. " garbage="map" i = 0 garbage.length.times do if garbage[i,1] =~ /^[a-z]/ if garbage[i,1] =~ /^[a-x]/ garbage[i] = garbage[i].next.next else garbage[i,1] =~ /^[x-z]/ garbage[i] = garbage[i] - 24 end end i += 1 end puts garbage
With the first garbage variable being the scramble message it returns the message to use the method on the url, which is the second garbage variable “map”, which transformed is “ocr”.
And on to the next challenge, number 2. The page presents a picture of a book and the this message;
recognize the characters. maybe they are in the book,
but MAYBE they are in the page source.
One nice thing about the python challenge is that after solving a puzzle they allow you to see how other people solved it, and solutions in any language you may be studying are likely there. Indeed there where two ruby solutions posted, including this one-liner;
which launched from the interactive shell prompts for input and translates it.
intrigued I looked up the tr method ‘ri String.tr’;
Thats how you learn.