From 0827c0f9ca1973226fccc28833fc62a09afb5f9f Mon Sep 17 00:00:00 2001 From: Jeff Yates Date: Sun, 6 Dec 2020 07:13:02 -0500 Subject: [PATCH] finished solution --- day05/solution01.rb | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 day05/solution01.rb diff --git a/day05/solution01.rb b/day05/solution01.rb new file mode 100755 index 0000000..a8c706f --- /dev/null +++ b/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 + \ No newline at end of file