[2020][ruby][5.x] too clever

pull/2/head
Alpha Chen 4 years ago
parent a369ffb751
commit cccdf1e45e

@ -1,21 +1,6 @@
id = proc {|r, c| r * 8 + c }
seats = ARGF.read.split("\n") seats = ARGF.read.split("\n")
.map {|pass| pass.tr("FB", "01").tr("LR", "01") } .map {|pass| pass.tr("FB", "01").tr("LR", "01") }
.map {|pass| pass.to_i(2) } .map {|pass| pass.to_i(2) }
.map {|pass| p seats.max # day 1
row = pass >> 3
col = pass & 0b111
[row, col]
}
# p seats.map(&id).max # day 1
rows = seats.map(&:first).minmax p (0b1000..).find {|id| !seats.include?(id) }
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]

Loading…
Cancel
Save