From c6a4013bc0657c5126be8f755cf6a6c898bc480f Mon Sep 17 00:00:00 2001 From: "Jan \"Yenya\" Kasprzak" Date: Thu, 2 Dec 2021 06:06:36 +0100 Subject: [PATCH] Day 2: pretty straightforward --- 03.pl | 13 +++++++++++++ 04.pl | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 03.pl create mode 100755 04.pl 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; + -- 2.43.0