From a369ffb7513e168cdce26d1dd37bea84692c2b29 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Fri, 4 Dec 2020 21:26:55 -0800 Subject: [PATCH] [2020][ruby][5.x] --- 2020/ruby/day_05.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 2020/ruby/day_05.rb diff --git a/2020/ruby/day_05.rb b/2020/ruby/day_05.rb new file mode 100644 index 0000000..9ec1fb4 --- /dev/null +++ b/2020/ruby/day_05.rb @@ -0,0 +1,21 @@ +id = proc {|r, c| r * 8 + c } + +seats = ARGF.read.split("\n") + .map {|pass| pass.tr("FB", "01").tr("LR", "01") } + .map {|pass| pass.to_i(2) } + .map {|pass| + row = pass >> 3 + col = pass & 0b111 + [row, col] + } +# p seats.map(&id).max # day 1 + +rows = seats.map(&:first).minmax +cols = seats.map(&:last).minmax +all_seats = Range.new(*rows).flat_map {|r| + Range.new(*cols).map {|c| + [r, c] + } +} +seat = (all_seats - seats).find {|r,_| !rows.include?(r) } +p id[*seat]