diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2020-12-25 15:15:18 +0100 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2020-12-25 15:15:18 +0100 |
commit | 8ef384f47d69ce346a523cc76f334b89712e8cab (patch) | |
tree | cfb35c9c252eff2692d5ad2750ccf8b63e5fb1e1 | |
parent | 8216a91439c30ba2c6f57a49be2daef7ec6e596c (diff) |
Add day 5
-rw-r--r-- | 05/a.rb | 11 | ||||
-rw-r--r-- | 05/b.rb | 15 |
2 files changed, 26 insertions, 0 deletions
@@ -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 @@ -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 |