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