Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my $horz = 0;
- my $aim = 0;
- my $depth = 0;
- while (<>) {
- my ($cmd, $mag) = split;
- if ($cmd eq 'forward') {
- $horz += $mag;
- $depth += $mag * $aim;
- } else {
- # Evil! level just happens to be a word between up and down
- $aim += ('level' cmp $cmd) * $mag;
- }
- }
- print "Part 1: ", $horz * $aim, "\n";
- print "Part 2: ", $horz * $depth, "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement