class No48 attr_accessor :width, :height, :distance, :count def initialize @width, @height, @distance = gets.chomp.to_i, gets.chomp.to_i, gets.chomp.to_i @count = 0 end def negative_number(num) if num < 0 num *= -1 @count += 1 end num end def move_on(num) unless num == 0 num < @distance ? num = 0 : num -= @distance @count += 1 end num end def run @width = self.negative_number(@width) @height = self.negative_number(@height) loop{ @width = self.move_on(@width) @height = self.move_on(@height) break if @width == 0 && @height == 0 } @count end end no48 = No48.new puts no48.run