diff options
Diffstat (limited to '2020/five.nim')
-rw-r--r-- | 2020/five.nim | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/2020/five.nim b/2020/five.nim new file mode 100644 index 0000000..ebad294 --- /dev/null +++ b/2020/five.nim @@ -0,0 +1,27 @@ +# Day Five: Binary Boarding +import os, math, std/enumerate + +let input: string = paramStr(1) + +var + min: int = 2^8 + max: int = 0 + flight: seq[int] +for seat in lines(input): + var row, column, id: int = 0 + for i, char in enumerate(seat[0..^4]): + if char == 'B': + row += 2^(7-i) div 2 + for i, char in enumerate(seat[7..^1]): + if char == 'R': + column += 2^(3-i) div 2 + id = row * 8 + column + max = max(max, id) + min = min(min, id) + flight.add(id) + +echo max + +for id in min .. max: + if id notin flight: + echo id |