|
|
|
@ -1,13 +1,11 @@
|
|
|
|
|
falling_bytes = DATA.read.scan(/\d+/).map(&:to_i).each_slice(2).to_a
|
|
|
|
|
|
|
|
|
|
corrupted = falling_bytes[0,1024]
|
|
|
|
|
|
|
|
|
|
max = 70
|
|
|
|
|
|
|
|
|
|
deltas = [[-1,0], [1,0], [0,-1], [0,1]]
|
|
|
|
|
MAX = 70
|
|
|
|
|
DELTAS = [[-1,0], [1,0], [0,-1], [0,1]]
|
|
|
|
|
|
|
|
|
|
def path(corrupted)
|
|
|
|
|
start = [0,0]
|
|
|
|
|
stop = [max,max]
|
|
|
|
|
stop = [MAX,MAX]
|
|
|
|
|
|
|
|
|
|
scores = Hash.new(Float::INFINITY)
|
|
|
|
|
scores[start] = 0
|
|
|
|
@ -17,10 +15,10 @@ until scores.has_key?(stop)
|
|
|
|
|
current = frontier.shift
|
|
|
|
|
visited << current
|
|
|
|
|
|
|
|
|
|
neighbors = deltas.map {|delta|
|
|
|
|
|
neighbors = DELTAS.map {|delta|
|
|
|
|
|
current.zip(delta).map { _1 + _2 }
|
|
|
|
|
}.select {|xy|
|
|
|
|
|
xy.all? { (0..max).cover?(_1) }
|
|
|
|
|
xy.all? { (0..MAX).cover?(_1) }
|
|
|
|
|
}.reject {|xy|
|
|
|
|
|
corrupted.include?(xy) || visited.include?(xy)
|
|
|
|
|
}
|
|
|
|
@ -34,7 +32,17 @@ until scores.has_key?(stop)
|
|
|
|
|
frontier.sort_by! { scores.fetch(_1) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
pp scores.fetch(stop)
|
|
|
|
|
scores.fetch(stop)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
i = (0...falling_bytes.length).bsearch {|i|
|
|
|
|
|
begin
|
|
|
|
|
path(falling_bytes[0,i]) && false
|
|
|
|
|
rescue
|
|
|
|
|
true
|
|
|
|
|
end
|
|
|
|
|
}
|
|
|
|
|
puts falling_bytes.fetch(i-1).join(?,)
|
|
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
54,47
|
|
|
|
|