optimized monty1.rb