adventofcode2020/5/5.py

46 lines
932 B
Python
Raw Normal View History

2020-12-06 10:26:58 -05:00
#!/usr/bin/env python3
import sys
L = []
with open(sys.argv[1], 'r') as f:
L = f.readlines()
L = [x.strip() for x in L]
# part 2
ids = []
# part 1
highestId = 0
for l in L:
row = [0, 128]
col = [0, 8]
for i in range(10):
if i < 7:
if l[i] == 'F':
row[1] -= (row[1] - row[0]) / 2
# print('F')
else:
row[0] += (row[1] - row[0]) / 2
# print('B')
# print(row)
else:
if l[i] == 'L':
col[1] -= (col[1] - col[0]) / 2
else:
col[0] += (col[1] - col[0]) / 2
ids.append(row[0] * 8 + col[0])
if ids[-1] > highestId:
highestId = ids[-1]
print(highestId)
# part 2
ids.sort()
prevId = ids[0]
missingPrevIds = []
for id in ids:
if prevId != id and prevId + 1 != id:
missingPrevIds.append(id)
prevId = id
print(missingPrevIds)