Solution code for Ruby Warrior