-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
42 lines (30 loc) · 932 Bytes
/
main.py
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
33
34
35
36
37
38
39
40
41
42
from src.common.file_utils import get_path, read_lines
def part_one(filename: str) -> int:
lines = read_lines(get_path(__file__, filename))
return max([get_seat_id(line) for line in lines])
def part_two(filename: str) -> int:
lines = read_lines(get_path(__file__, filename))
seat_ids = sorted([get_seat_id(line) for line in lines])
missing = seat_ids[0]
for s in seat_ids:
missing ^= s
return missing
def get_seat_id(line):
row, mask = 0, 64
for r in line[0:7]:
if r == "B":
row += mask
mask >>= 1
col, mask = 0, 4
for c in line[7:10]:
if c == "R":
col += mask
mask >>= 1
return (row * 8) + col
if __name__ == '__main__':
print("---Part One---")
part_one_res = part_one("input.txt")
print(part_one_res)
print("---Part Two---")
part_two_res = part_two("input.txt")
print(part_two_res)