Created
November 20, 2022 12:12
-
-
Save turbod/feff692f70f2c63d9c0328ea9405f7a9 to your computer and use it in GitHub Desktop.
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
STDOUT.sync = true # DO NOT REMOVE | |
# Auto-generated code below aims at helping you parse | |
# the standard input according to the problem statement. | |
# w: width of the building. | |
# h: height of the building. | |
@w, @h = gets.split(" ").collect {|x| x.to_i} | |
@n = gets.to_i # maximum number of turns before game over. | |
@x, @y = gets.split(" ").collect {|x| x.to_i} | |
@min_x = 0 | |
@max_x = @w - 1 | |
@min_y = 0 | |
@max_y = @h - 1 | |
# game loop | |
loop do | |
bomb_dir = gets.chomp # the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL) | |
bomb_dir.split('').each do |c| | |
case c | |
when ?U | |
@max_y = @y - 1 | |
when ?D | |
@min_y = @y + 1 | |
when ?L | |
@max_x = @x - 1 | |
when ?R | |
@min_x = @x + 1 | |
end | |
end | |
@x = (@min_x + @max_x ) / 2 | |
@y = (@min_y + @max_y ) / 2 | |
puts "#{@x} #{@y}" # the location of the next window Batman should jump to. | |
end | |
# 0 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment