]> www.fi.muni.cz Git - aoc2021.git/blobdiff - 04.pl
Day 2: pretty straightforward
[aoc2021.git] / 04.pl
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;
+