From: Jan "Yenya" Kasprzak Date: Thu, 2 Dec 2021 05:06:36 +0000 (+0100) Subject: Day 2: pretty straightforward X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=aoc2021.git;a=commitdiff_plain;h=c6a4013bc0657c5126be8f755cf6a6c898bc480f Day 2: pretty straightforward --- diff --git a/03.pl b/03.pl new file mode 100755 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 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; +