Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 35 lines (30 sloc) 0.678 kB
#!/usr/bin/env ruby -w
DISPLAY = ARGV.delete("-d")
units = ARGF.gets.to_i
cave = [ ]
ARGF.each do |line|
next unless line =~ /\S/ # skip blank lines
cave << line.strip.split("")
end
(units - 1).times do
catch :added do
cave.each_with_index.reverse_each do |row, y|
row.each_with_index.reverse_each do |cell, x|
if cell == " " and (cave[y - 1][x] == "~" or cave[y][x - 1] == "~")
cell.replace("~")
throw :added
end
end
end
end
end
if DISPLAY
cave.each do |row|
puts row.join
end
puts
end
puts cave.transpose.map { |column|
str = column.join
str.include?("~ ") ? "~" : str.count("~")
}.join(" ")
Jump to Line
Something went wrong with that request. Please try again.