]> www.fi.muni.cz Git - aoc.git/commitdiff
Day 2: pretty straightforward
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Thu, 2 Dec 2021 05:06:36 +0000 (06:06 +0100)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Thu, 2 Dec 2021 05:06:36 +0000 (06:06 +0100)
03.pl [new file with mode: 0755]
04.pl [new file with mode: 0755]

diff --git a/03.pl b/03.pl
new file mode 100755 (executable)
index 0000000..47683ee
--- /dev/null
+++ b/03.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/perl -w
+
+use v5.16;
+
+my ($x, $z) = (0, 0);
+while (<>) {
+       my ($dir, $num) = split /\s+/;
+       $x+=$num if $dir eq 'forward';
+       $z+=$num if $dir eq 'down';
+       $z-=$num if $dir eq 'up';
+}
+say $x*$z;
+
diff --git a/04.pl b/04.pl
new file mode 100755 (executable)
index 0000000..78106cf
--- /dev/null
+++ b/04.pl
@@ -0,0 +1,16 @@
+#!/usr/bin/perl -w
+
+use v5.16;
+
+my ($x, $z, $aim) = (0, 0, 0);
+while (<>) {
+       my ($dir, $num) = split /\s+/;
+       if ($dir eq 'forward') {
+               $x += $num;
+               $z += $aim*$num;
+       }
+       $aim+=$num if $dir eq 'down';
+       $aim-=$num if $dir eq 'up';
+}
+say $x*$z;
+