aboutsummaryrefslogtreecommitdiff
path: root/2020/five.nim
blob: ebad294141c4eccb52aa3a4943e9552c8a0cd88f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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