about summary refs log tree commit diff
path: root/day08.ijs
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2020-12-09 19:11:42 +0100
committerLeah Neukirchen <leah@vuxu.org>2020-12-09 19:11:42 +0100
commita521c98193a01927f5d4f7aa245a6fc9ca7d8ad9 (patch)
tree3b631f6a74f94cff2e3c6461a5b23b72dd5e2298 /day08.ijs
parent994a71edcd0353bddf71008fd5599c97098a966c (diff)
downloadadventofcode2020-a521c98193a01927f5d4f7aa245a6fc9ca7d8ad9.tar.gz
adventofcode2020-a521c98193a01927f5d4f7aa245a6fc9ca7d8ad9.tar.xz
adventofcode2020-a521c98193a01927f5d4f7aa245a6fc9ca7d8ad9.zip
day08
Diffstat (limited to 'day08.ijs')
-rw-r--r--day08.ijs18
1 files changed, 18 insertions, 0 deletions
diff --git a/day08.ijs b/day08.ijs
new file mode 100644
index 0000000..c3bbeef
--- /dev/null
+++ b/day08.ijs
@@ -0,0 +1,18 @@
+load 'aoc.ijs'
+p =: |:({."1 r),:v =. ". each 1 }"1 r =. cutopen every lines 'day08'
+
+step =: 4 : 0
+'ip acc' =. y
+if. ip >: # x do.
+  (#x),acc
+else.
+  'o n' =. ip { x
+  (>:ip + (o -: 'jmp')*<:n),acc + n * (o -: 'acc')
+end.
+)
+
+([: }. ] {~ [: (~: i. 0:) {."1) p&step^:(<1000) 0 0   NB. 1451
+
+patch =: ] 0}~ [: ((,|.)'jmp';'nop')&stringreplace&.> 0 { ]
+rs =: 3 : '(( p (y }~) (patch y { p) )&step^:1000) 0 0'
+{: rp {~ (#p) i.~ {."1 rp =: rs"0 i. #p  NB.  1160