Revised by
cia_rana
4c15e3c
| def to_right_child x, y
[y - x, y]
end
def to_left_child x, y
[x, x + y]
end
def from_right_child x, y
[y - x, y]
end
def from_left_child x, y
[x, y - x]
end
def decide_right x, y
i = 0
a, b = x, y
loop do
return [?-] if a * 2 == b
c, d = from_left_child(a, b)
if c > d
a, b = from_right_child(a, b)
elsif c * 2 < d
a, b = to_right_child(c, d)
break
else
a, b = c, d
end
i += 1
end
[a, a * i + b]
end
def decide_left x, y
i = 0
a, b = x, y
loop do
return [?-] if a * 2 == b
c, d = from_left_child(a, b)
if c > d
a, b = to_left_child *from_right_child(a, b)
break
else
a, b = c, d
end
i += 1
end
1.upto(i){ a, b = a * 2 > b ? to_left_child(a, b) : to_right_child(a, b) }
[a, b]
end
x, y = gets.scan(/\d+/).map(&:to_i)
puts decide_left(x, y)*?/ + ?, + decide_right(x, y)*?/
|