-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday5.py
More file actions
39 lines (34 loc) · 1.02 KB
/
day5.py
File metadata and controls
39 lines (34 loc) · 1.02 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
import numpy as np
import pandas as pd
import re
with open('/Users/relyea/data/input_day5.txt') as aoc_fp:
input_data = [theline.rstrip() for theline in aoc_fp.readlines()]
def find_seat(seatstr):
# ohhh it's just binary - I'm a tool
rangetop = 128
rangebot = 0
aislebot = 0
aisletop = 8
rowrange = 128
aislerange = 8
for seatchar in seatstr[0:7]:
rowrange = rowrange/2
if seatchar == 'F':
rangetop = rangebot + rowrange
elif seatchar == 'B':
rangebot = rangetop - rowrange
for seatchar in seatstr[7:]:
aislerange = aislerange/2
if seatchar == 'L':
aisletop = aislebot + aislerange
elif seatchar == 'R':
aislebot = aisletop - aislerange
return (rangetop-1)*8+ (aisletop-1)
maxseat = 0
for line in input_data:
if find_seat(line) > maxseat:
maxseat = find_seat(line)
print(maxseat)
seat_exist = np.zeros(int(maxseat))
for line in input_data:
seat_exist[int(find_seat(line))-1] = 1