-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay11.py
48 lines (39 loc) · 1.04 KB
/
Day11.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
# AOC17 day 11
def calculate(path):
# using a skewed coordinate system
max_dist = 0
row, col = 0, 0
trans = {"n": (-1, 0),
"s": (1, 0),
"nw": (0, -1),
"se": (0, 1),
"ne": (-1, 1),
"sw": (1, -1)}
for move in path:
row += trans[move][0]
col += trans[move][1]
if dist(row, col) > max_dist:
max_dist = dist(row, col)
return dist(row, col), max_dist
def dist(row, col):
# distance from 0, 0
d = 0
if row > 0 > col:
d += min(row, -col)
row -= d
col += d
if row < 0 < col:
d += min(-row, col)
row += d
col -= d
d += max(abs(row), abs(col))
return d
def load_data(f_name):
with open(f_name, "r") as f:
data_read = f.read()
return data_read
def run():
data = load_data("Day11.txt")
path = data.split(",")
end_dist, max_dist = calculate(path)
print(f"The child program is {end_dist} tiles away and was at most {max_dist} tiles away")