From cccdf1e45e498c525b903975ee61d6a19aec74a1 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sat, 5 Dec 2020 06:50:23 -0800 Subject: [PATCH] [2020][ruby][5.x] too clever --- 2020/ruby/day_05.rb | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/2020/ruby/day_05.rb b/2020/ruby/day_05.rb index 9ec1fb4..b369b64 100644 --- a/2020/ruby/day_05.rb +++ b/2020/ruby/day_05.rb @@ -1,21 +1,6 @@ -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 +p seats.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] +p (0b1000..).find {|id| !seats.include?(id) }