Skip to content

Instantly share code, notes, and snippets.

@ninoseki
Last active August 29, 2015 14:14
Show Gist options
  • Save ninoseki/71a4f891d02df6e3b96a to your computer and use it in GitHub Desktop.
Save ninoseki/71a4f891d02df6e3b96a to your computer and use it in GitHub Desktop.
Codeforces#290 Div2-A
# http://codeforces.com/contest/510/problem/A
class Snake
def initialize(n, m)
@n, @m = n, m
end
def draw
rows.each { |row| puts row.join }
end
private
def rows
[].tap do |rows|
@n.times do |idx|
case
when idx.even?
rows << ['#'] * @m
when rows[idx - 2].nil?, rows[idx - 2].first == '#'
rows << ['.'] * (@m - 1) + ['#']
else
rows << ['#'] + ['.'] * (@m - 1)
end
end
end
end
end
n, m = gets.chomp.split.map(&:to_i)
snake = Snake.new(n, m)
snake.draw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment