aoc2020/5.py

38 lines
637 B
Python
Raw Normal View History

2020-12-06 08:59:02 +00:00
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):