Problem 36 done in Ruby.