Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use feature qw(say);
- my @input = map { y#LR#- #; int $_ } <>;
- my $part1 = 0;
- my $part2 = 0;
- my $pos = 50;
- foreach my $move (@input) {
- # Multiple rotations
- $part2 += int(abs($move) / 100);
- $move = $move % (100 * ($move <=> 0)); # mod maintaining direction (sign)
- # Move through/to 0 (but not from, as that would double count)
- my $new_pos = $pos + $move;
- $part2++ if ($pos and !(0 < $new_pos < 100));
- $pos = $new_pos % 100;
- $part1++ if (!$pos);
- }
- say "Part 1: $part1";
- say "Part 2: $part2";
Advertisement
Add Comment
Please, Sign In to add comment