2020 Advent of Code solutions in various languages
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

43 lines
642 B

import math
import numpy as np
with open("../input/05-01.txt") as f:
input = f.read().splitlines()
def partition(seq, lb, ub, trigger, ret):
for idx, part in enumerate(seq):
amt = math.floor((ub - lb)/2) + 1
if (part == trigger):
ub -= amt
else:
lb += amt
return(ub if (seq[-1] == trigger) else lb)
def get_seat(x):
return(
(partition(x[0:7], 0, 127, "F", "F") * 8) +
partition(x[7:10], 0, 7, "L", "L")
)
res = [ get_seat(bpass) for bpass in input ]
# 05-01
res.sort()
max(res)
# 05-02
res.insert(0, res[0])
idx = np.where(np.diff(res) > 1)
res.pop(0)
res[idx[0][0]] - 1