Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
xtetsuji-juku
#!/usr/bin/env ruby
(y, x) = gets.chomp.split(/ /).map(&:to_i)
now = [1, 1]
addy = 1
addx = 1
puts "#{now[0]}, #{now[1]}"
while
now[0] += addy
now[1] += addx
if now[0] + now[1] == 2 || now[0] + now[1] == y + x
break
elsif (now[0] == 1 && now[1] == x) || (now[0] == y && now[1] == 1)
break
else
if now[0] == y || now[0] == 1
addy = addy * -1
end
if now[1] == x || now[1] == 1
addx = addx * -1
end
end
puts "#{now[0]}, #{now[1]}"
end
puts "#{now[0]}, #{now[1]}"
puts "GOAL!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment