diff options
author | Leah Neukirchen <leah@vuxu.org> | 2019-12-04 16:51:50 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2019-12-04 16:51:50 +0100 |
commit | c612a380785d0f9fec1cf9494386beb271cf1d3c (patch) | |
tree | 2b782536345a01b5454b41d9da4ec12caade1c0a /day02.pl | |
parent | 95e458366fac25a992307d4acc396d143345c102 (diff) | |
download | adventofcode2019-c612a380785d0f9fec1cf9494386beb271cf1d3c.tar.gz adventofcode2019-c612a380785d0f9fec1cf9494386beb271cf1d3c.tar.xz adventofcode2019-c612a380785d0f9fec1cf9494386beb271cf1d3c.zip |
day02
Diffstat (limited to 'day02.pl')
-rw-r--r-- | day02.pl | 25 |
1 files changed, 25 insertions, 0 deletions
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; + } +} |