aboutsummaryrefslogtreecommitdiff
path: root/2019
diff options
context:
space:
mode:
Diffstat (limited to '2019')
-rw-r--r--2019/07/Makefile1
-rwxr-xr-x2019/07/machine.lisp6
-rwxr-xr-x2019/07/puzzle-1.sh14
-rwxr-xr-x2019/07/puzzle-2.sh19
4 files changed, 40 insertions, 0 deletions
diff --git a/2019/07/Makefile b/2019/07/Makefile
new file mode 100644
index 0000000..5a21270
--- /dev/null
+++ b/2019/07/Makefile
@@ -0,0 +1 @@
+include ../../Makefiles/lisp.mk \ No newline at end of file
diff --git a/2019/07/machine.lisp b/2019/07/machine.lisp
new file mode 100755
index 0000000..798bbb8
--- /dev/null
+++ b/2019/07/machine.lisp
@@ -0,0 +1,6 @@
+#!/usr/bin/sbcl --script
+
+(load "../interpreter.lisp")
+
+(intcode:run (intcode:parse "input") *standard-input* *standard-output*
+ :initial-arguments (mapcar #'parse-integer (cdr *posix-argv*))) \ No newline at end of file
diff --git a/2019/07/puzzle-1.sh b/2019/07/puzzle-1.sh
new file mode 100755
index 0000000..38fd725
--- /dev/null
+++ b/2019/07/puzzle-1.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+python -c '
+import itertools
+for p in itertools.permutations([0, 1, 2, 3, 4]):
+ print(*p)
+' | while read a b c d e
+do
+ ./machine.lisp $a 0 \
+ | ./machine.lisp $b \
+ | ./machine.lisp $c \
+ | ./machine.lisp $d \
+ | ./machine.lisp $e
+done | sort -nr | head -n1 \ No newline at end of file
diff --git a/2019/07/puzzle-2.sh b/2019/07/puzzle-2.sh
new file mode 100755
index 0000000..4a034f7
--- /dev/null
+++ b/2019/07/puzzle-2.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+mkfifo pipe
+trap 'rm pipe' EXIT
+
+python -c '
+import itertools
+for p in itertools.permutations([5, 6, 7, 8, 9]):
+ print(*p)
+' | while read a b c d e
+do
+ ./machine.lisp $a 0 <pipe \
+ | ./machine.lisp $b \
+ | ./machine.lisp $c \
+ | ./machine.lisp $d \
+ | ./machine.lisp $e \
+ | tee pipe \
+ | tail -n1
+done | sort -nr | head -n1 \ No newline at end of file