My code to pass until 9th level of the Ruby Warrior game