summaryrefslogtreecommitdiffstats
path: root/19
diff options
context:
space:
mode:
authorGustav Sörnäs <gusso230@student.liu.se>2019-12-21 18:12:32 +0100
committerGustav Sörnäs <gusso230@student.liu.se>2019-12-21 20:29:35 +0100
commit49280f2be70142633639618c8f8af0eb807fe429 (patch)
treec95426f9cc92dcc68a1627890c71f39dc152b9e0 /19
parent6648b90e324ef95c072a17daf4173b2334f08d57 (diff)
downloadaoc-49280f2be70142633639618c8f8af0eb807fe429.tar.gz
Separate solutions for day 21
Diffstat (limited to '19')
-rw-r--r--19/py/21-1.js10
-rw-r--r--19/py/21-2.js23
-rw-r--r--19/py/21.js14
-rw-r--r--19/py/d21.py40
4 files changed, 56 insertions, 31 deletions
diff --git a/19/py/21-1.js b/19/py/21-1.js
new file mode 100644
index 0000000..050352c
--- /dev/null
+++ b/19/py/21-1.js
@@ -0,0 +1,10 @@
+// A or B or C:
+// There is a gap somewhere in the next 3 tiles so we need to jump
+or A T
+and B T
+and C T
+not T J
+// . and D
+// We don't die if we jump
+and D J
+walk
diff --git a/19/py/21-2.js b/19/py/21-2.js
new file mode 100644
index 0000000..5f65fa1
--- /dev/null
+++ b/19/py/21-2.js
@@ -0,0 +1,23 @@
+// A or B or C:
+// There is a gap somewhere in the next 3 tiles so we need to jump
+or A T
+and B T
+and C T
+not T J
+// . and D
+// We don't die if we jump
+and D J
+// (postfix)
+// . and (H or EI or EF)
+// H : We can immediatly jump again
+// EI: We can walk one step and then jump again
+// EF: We can walk two steps (and then potentially jump again)
+// We don't have any information about tiles after I so we ignore and hope for
+// the best
+not F T
+not T T
+or I T
+and E T
+or H T
+and T J
+run
diff --git a/19/py/21.js b/19/py/21.js
deleted file mode 100644
index 7267d45..0000000
--- a/19/py/21.js
+++ /dev/null
@@ -1,14 +0,0 @@
-# part1
-or A T
-and B T
-and C T
-not T J
-and D J
-# part2
-not F T
-not T T
-or I T
-and E T
-or H T
-and T J
-run
diff --git a/19/py/d21.py b/19/py/d21.py
index b4ad1eb..84f01ff 100644
--- a/19/py/d21.py
+++ b/19/py/d21.py
@@ -1,10 +1,5 @@
import intcode
-f = open("../input/21", "r").readlines()
-
-c = intcode.Computer([int(x) for x in f[0].split(",")], ascii=True)
-output = []
-
def ascii_draw(a):
s = ""
for c in a:
@@ -16,16 +11,27 @@ def ascii_draw(a):
print("[INVALID ASCII]", c)
return s
-jumpscript = open("21.js", "r").readlines()
-for line in jumpscript:
- if line[0] != "#":
- c.queue_ascii(line.strip().upper())
- print(line.strip().upper())
+def do(c, jumpscript):
+ output = []
+ for line in jumpscript:
+ if line[:2] != "//":
+ c.queue_ascii(line.strip().upper())
+ while not c.SIG_HALT:
+ c.step()
+ if c.SIG_OUTPUT:
+ output.append(c.output)
+ c.output = None
+ return ascii_draw(output)
+
+def pt1(input):
+ c = intcode.Computer([int(x) for x in input[0].split(",")], ascii=True)
+ return do(c, open("21-1.js", "r").readlines())
+
+def pt2(input):
+ c = intcode.Computer([int(x) for x in input[0].split(",")], ascii=True)
+ return do(c, open("21-2.js", "r").readlines())
-while not c.SIG_HALT:
- c.step()
- if c.SIG_OUTPUT:
- output.append(c.output)
- c.output = None
-print(output)
-print(ascii_draw(output))
+if __name__ == "__main__":
+ input = open("../input/21", "r").readlines()
+ print(pt1(input))
+ print(pt2(input))