Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created September 10, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/df9725dee053c5dbc6d8 to your computer and use it in GitHub Desktop.
Save anonymous/df9725dee053c5dbc6d8 to your computer and use it in GitHub Desktop.
def open (file)
line = file.gets;
opencells = 0;
puts "this is reached"
puts "#{opencells}";
if line == nil then return end
# read additional lines
while line = file.gets do
# begins with "path", must be path specification
if line[0...4] == "path"
p, name, x, y, ds = line.split(/\s/)
# otherwise must be cell specification (since maze spec must be valid)
else
x, y, ds, w = line.split(/\s/,4)
#puts "cell spec: coordinates (#{x},#{y}) with dirs #{ds}"
#check if all four walls are open
check = true;
if ds.length == 4
4.times do |i|
case ds[i]
when "u", "d", "l", "r"
check = true;
else
check = false;
end
if check == false
break;
end
end
end
if check == true
opencells = opencells + 1;
end
end
end
puts "#{opencells}";
end
open(maze_file);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment