adventofcode/2021/02/part2.pm

28 lines
468 B
Perl
Raw Normal View History

2021-12-05 16:44:39 +00:00
package part2;
use 5.34.0;
use experimental qw/ signatures switch/;
sub solution(@lines) {
my( $depth, $aim, $x );
for my $line ( @lines ) {
my( $action, $value ) = split ' ', $line;
given($action) {
$aim+=$value when 'down';
$aim-=$value when 'up';
when( 'forward' ) {
$x += $value;
$depth += $aim * $value;
}
}
}
return $x * $depth;
}
1;