-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday_5
More file actions
39 lines (29 loc) · 1.04 KB
/
day_5
File metadata and controls
39 lines (29 loc) · 1.04 KB
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
# Read input
list_of_boarding_passes = open('input.txt').read().split('\n')
def split_list(local_char, local_list):
local_length = len(local_list)
local_middle_index = local_length // 2
local_lower_half = local_list[:local_middle_index]
local_upper_half = local_list[local_middle_index:]
if local_char in ('FL'):
return(local_lower_half)
elif local_char in ('BR'):
return(local_upper_half)
# Part One
seat_id_list = []
for boarding_pass in list_of_boarding_passes:
seat = list(range(128))
column = list(range(8))
for b in boarding_pass:
if b in ('FB'):
seat = split_list(b, seat)
if b in ('RL'):
column = split_list(b, column)
seat_id = (seat[0] * 8 + column[0])
seat_id_list.append(seat_id)
print('the highest seat id: ', max(seat_id_list))
# Part Two
seat_id_list.sort()
for seat_id_lower, seat_id_upper in zip(seat_id_list[:-1], seat_id_list[1:]):
if seat_id_upper - seat_id_lower == 2:
print('your seat id: ', (seat_id_lower + 1))