-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday05.py
More file actions
32 lines (28 loc) · 805 Bytes
/
day05.py
File metadata and controls
32 lines (28 loc) · 805 Bytes
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
28
29
30
31
32
rows = list(range(128))
cols = list(range(8))
def find_row(rows, chars):
l = len(rows)
if l == 1:
return rows[0]
if chars[0] in ('F', 'L'):
return find_row(rows[:l//2], chars[1:])
else:
return find_row(rows[l//2:], chars[1:])
def part2(seats):
seats.sort()
for i, n in enumerate(seats[1:-1]):
if seats[i] != n-1:
return (n-1)
if seats[i+2] != n+1:
return (n+1)
def main(inp):
with open(inp) as f:
lines = f.read().splitlines()
seats = [8 * find_row(rows, line[:7]) + find_row(cols, line[-3:]) for line in lines]
res1 = max(seats)
res2 = part2(seats)
return res1, res2
if __name__ == '__main__':
a, b = main('../input/input05.txt')
print('day05.1:', a)
print('day05.2:', b)