about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2019-12-04 16:51:50 +0100
committerLeah Neukirchen <leah@vuxu.org>2019-12-04 16:51:50 +0100
commitc612a380785d0f9fec1cf9494386beb271cf1d3c (patch)
tree2b782536345a01b5454b41d9da4ec12caade1c0a
parent95e458366fac25a992307d4acc396d143345c102 (diff)
downloadadventofcode2019-c612a380785d0f9fec1cf9494386beb271cf1d3c.tar.gz
adventofcode2019-c612a380785d0f9fec1cf9494386beb271cf1d3c.tar.xz
adventofcode2019-c612a380785d0f9fec1cf9494386beb271cf1d3c.zip
day02
-rw-r--r--day021
-rw-r--r--day02.k8
-rw-r--r--day02.pl25
3 files changed, 34 insertions, 0 deletions
diff --git a/day02 b/day02
new file mode 100644
index 0000000..96dc297
--- /dev/null
+++ b/day02
@@ -0,0 +1 @@
+1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,6,1,19,1,19,5,23,2,9,23,27,1,5,27,31,1,5,31,35,1,35,13,39,1,39,9,43,1,5,43,47,1,47,6,51,1,51,13,55,1,55,9,59,1,59,13,63,2,63,13,67,1,67,10,71,1,71,6,75,2,10,75,79,2,10,79,83,1,5,83,87,2,6,87,91,1,91,6,95,1,95,13,99,2,99,13,103,1,103,9,107,1,10,107,111,2,111,13,115,1,10,115,119,1,10,119,123,2,13,123,127,2,6,127,131,1,13,131,135,1,135,2,139,1,139,6,0,99,2,0,14,0
\ No newline at end of file
diff --git a/day02.k b/day02.k
new file mode 100644
index 0000000..ef8c522
--- /dev/null
+++ b/day02.k
@@ -0,0 +1,8 @@
+od:`i$","\:1:`day02
+v:{d::od; d[1 2]:x; {~99=d x}{d[d x+3]:((;+;*)d x)[d d x+1;d d x+2]; x+4}/0; *d}
+
+v 12 2
+100/:,/(19690720=v@)#+!99 99
+\\
+4090689
+7733
diff --git a/day02.pl b/day02.pl
new file mode 100644
index 0000000..3d83a7a
--- /dev/null
+++ b/day02.pl
@@ -0,0 +1,25 @@
+#!/usr/bin/perl -w
+use v5.16;
+
+use File::Slurper 'read_text';
+
+my @od = split ",", read_text "day02";
+my $p2 = 19690720;
+
+for my $n (0..99) {
+    for my $v(0..99) {
+        my @d = @od;
+        @d[1, 2] = ($n, $v);
+
+        for (my $ip = 0; $d[$ip] != 99; $ip += 4) {
+            if ($d[$ip] == 1) {
+                $d[$d[$ip+3]] = $d[$d[$ip+1]] + $d[$d[$ip+2]];
+            } elsif ($d[$ip] == 2) {
+                $d[$d[$ip+3]] = $d[$d[$ip+1]] * $d[$d[$ip+2]];
+            }
+        }
+        
+        say $d[0]  if $n == 12 && $v == 2;
+        say(100*$n+$v)  if $d[0] == 19690720;
+    }
+}