"Python Challenge".sub("Python", "Ruby")
I just found this great page: Python Challenge. Its a set of puzzles of increasing difficulty that you are supposed to solve using python (and your brain). Its a great way to learn Python along the way.
Of course, you can use other languages as well and like most of the time, Ruby is especially suited as well. Here is a solution to level 2 (don’t continue reading if you want to do it yourself):
Suppose the data is in a file “ocr.html”. Then these 3 lines do the trick:
data = IO.read("ocr.html").scan(/./)
hist = data.inject(Hash.new(0)) {|h,c| h[c] += 1; h}
print data.select{|c| hist[c] == 1}
Right now, I’m at level 5 (of 30). I wonder, how far Ruby will take me… :)