Created
July 25, 2020 12:44
-
-
Save tomcha/363a26e903db7697b6e40ccb4154ae86 to your computer and use it in GitHub Desktop.
xtetsuji-juku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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