graveyard/aoc2020/5.py
2022-05-09 11:58:15 -05:00

37 lines
637 B
Python

def search(n):
first7 = n[:7]
lo = 0
hi = 128
for c in first7:
mid = (lo + hi) // 2
if c == "F":
hi = mid
elif c == "B":
lo = mid
x = lo
last3 = n[-3:]
lo = 0
hi = 8
for c in last3:
mid = (lo + hi) // 2
if c == "L":
hi = mid
elif c == "R":
lo = mid
y = lo
id = 8 * x + y
return id
ids = []
with open("5.txt") as f:
for line in f:
line = line.strip()
id = search(line)
ids.append(id)
ids.sort()
print(ids)
print("ajsdoifapjds")
for i in range(len(ids) - 3):