finished solution

master
Jeff Yates 2 years ago
parent ce5312d26c
commit 0827c0f9ca
  1. 34
      day05/solution01.rb

@ -0,0 +1,34 @@
#!/bin/env ruby
ids = []
File.readlines('./input').each do |line|
line.strip!
row = [0, 127]
col = [0, 7]
step = 64
line[..6].each_char do |char|
row[0] += step if char == 'B'
row[1] -= step if char == 'F'
step /= 2
end
step = 4
line[-3..].each_char do |char|
col[0] += step if char == 'R'
col[1] -= step if char == 'L'
step /= 2
end
id = (row[0] * 8) + col[0]
ids.push(id)
puts "Seat #{line} is at row #{row} and column #{col}. Seat id: #{id}"
end
puts "The highest seat ID is #{ids.max}"
ids.sort!
ids.each_index do |i|
next if i == 0
if ids[i] != (ids[i-1] + 1)
puts "My seat is #{ids[i] - 1}"
break
end
end
Loading…
Cancel
Save