commit 60023b5c24c3928830ab0f4766a89931bb8cf87e
parent ac00187220e936637b7ec4073ec8b6d4272fd805
Author: mpizzzle <michael.770211@gmail.com>
Date: Thu, 14 Dec 2017 22:20:33 +0000
puzzle 11 complete
Diffstat:
2 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/puzzle11.py b/puzzle11.py
@@ -0,0 +1,52 @@
+x, y = [0.0], [0.0]
+
+def find_least_steps(direction):
+ step(direction)
+ cur_x, cur_y = x[0], y[0]
+ steps = 0
+
+ while x[0] != 0:
+ if x[0] < 0:
+ if y[0] < 0:
+ step("ne")
+ else:
+ step("se")
+ else:
+ if y[0] < 0:
+ step("nw")
+ else:
+ step("sw")
+ steps += 1
+ while y[0] != 0:
+ if y[0] < 0:
+ step("n")
+ else:
+ step("s")
+ steps += 1
+
+ x[0], y[0] = cur_x, cur_y
+ return steps
+
+def step(direction):
+ if direction == "n":
+ y[0] += 1
+ if direction == "s":
+ y[0] -= 1
+ if direction == "nw":
+ x[0] -= 1
+ y[0] += 0.5
+ if direction == "ne":
+ x[0] += 1
+ y[0] += 0.5
+ if direction == "sw":
+ x[0] -= 1
+ y[0] -= 0.5
+ if direction == "se":
+ x[0] += 1
+ y[0] -= 0.5
+
+with open('files/puzzle11.txt') as f:
+ furthest_steps = max([find_least_steps(direction) for direction in f.read().strip().split(',')])
+
+print find_least_steps("")
+print furthest_steps
diff --git a/puzzle12.py b/puzzle12.py
@@ -1,5 +1,3 @@
-from sets import Set
-
with open('files/puzzle12.txt') as f:
programs = f.readlines()