Part 1 ported to Ruby