Last active
August 29, 2015 14:14
-
-
Save ninoseki/71a4f891d02df6e3b96a to your computer and use it in GitHub Desktop.
Codeforces#290 Div2-A
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
# 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