Puzzle solver in ruby