From 8ef384f47d69ce346a523cc76f334b89712e8cab Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 25 Dec 2020 15:15:18 +0100 Subject: Add day 5 --- 05/a.rb | 11 +++++++++++ 05/b.rb | 15 +++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 05/a.rb create mode 100644 05/b.rb (limited to '05') diff --git a/05/a.rb b/05/a.rb new file mode 100644 index 0000000..877abb9 --- /dev/null +++ b/05/a.rb @@ -0,0 +1,11 @@ +max = 0 +File.readlines('input.txt').map do |line| + line.tr('FBLR', '0101') +end.each do |line| + row = line.slice(0, 7).to_i 2 + seat = line.slice(7, 3).to_i 2 + id = row * 8 + seat + max = [id, max].max +end + +puts max diff --git a/05/b.rb b/05/b.rb new file mode 100644 index 0000000..378f7c6 --- /dev/null +++ b/05/b.rb @@ -0,0 +1,15 @@ +missing = 0 +File.readlines('input.txt').map do |line| + line.tr('FBLR', '0101') +end.map do |line| + row = line.slice(0, 7).to_i 2 + seat = line.slice(7, 3).to_i 2 + row * 8 + seat +end.sort.reduce do |last_seen, current| + if current - 1 != last_seen + missing = current - 1 + end + current +end + +puts missing -- cgit v1.2.3