Advent of Code solutions
1#!/usr/bin/perl
2
3$horizontal = 0;
4$depth = 0;
5$aim = 0;
6
7while(<>) {
8 $command = $_;
9
10 if ($command =~ /forward (\d+)/) {
11 $horizontal += $1;
12 $depth += $aim * $1;
13 } elsif ($command =~ /up (\d+)/) {
14 $aim -= $1;
15 } elsif ($command =~ /down (\d+)/) {
16 $aim += $1;
17 }
18}
19
20print $depth * $horizontal . "\n";