1
2
3
4
5
6
7
8
9
10
11
12
13
14
floor = DATA.read.strip.each_char.with_index.inject(0) do |n,(i,index)|
  puts "Entered basement at index #{index}" if n == -1
  n + case i
      when ?(
        1
      when ?)
        -1
      else
        fail "Unexpected input: #{i.inspect}"
      end
end

puts floor
__END__