Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created July 25, 2020 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomcha/5b6fbee7cb92a851081930c85e46cf17 to your computer and use it in GitHub Desktop.
Save tomcha/5b6fbee7cb92a851081930c85e46cf17 to your computer and use it in GitHub Desktop.
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] - now[1]).abs == (x - y).abs
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