-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdayFive.py
58 lines (47 loc) · 1.23 KB
/
dayFive.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# q1
import math
boarding_passes = []
with open("dayFive.txt") as file:
for line in file:
boarding_passes.append(line.strip())
def evalRow(code):
low = 0
high = 127
curr = 0
for char in code:
if char == "F":
high = math.floor((low + high) / 2)
curr = high
else:
low = math.ceil((low + high) / 2)
curr = low
return curr
def evalCol(code):
low = 0
high = 7
curr = 0
for char in code:
if char == "L":
high = math.floor((low + high) / 2)
curr = high
else:
low = math.ceil((low + high) / 2)
curr = low
return curr
def getId(code):
row_val = evalRow(code[:7])
col_val = evalCol(code[7:])
return (row_val* 8) + col_val
max_id = 0
for code in boarding_passes:
curr_id = getId(code)
max_id = max(max_id, curr_id)
print(f"The highest seat ID is {max_id}")
# q2
sum_ids = 0
for code in boarding_passes:
current_id = getId(code)
sum_ids += current_id
# min ID (32) was calculated by slightly altering # q1 solutuion
missing_id = sum([x for x in range(32, 849)]) - sum_ids
print(f"Missing seat ID (my seat ID) is {missing_id}")