Solution 8 in Ruby
Solution 9 in Ruby
Solution 9 in JS