mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
39 lines
551 B
Perl
Executable File
39 lines
551 B
Perl
Executable File
#!/usr/bin/perl
|
|
my @instructions;
|
|
|
|
for $line ( <STDIN> ) {
|
|
push @instructions, $line;
|
|
}
|
|
|
|
@instructions2 = @instructions;
|
|
|
|
$iptr = 0;
|
|
|
|
$steps = 0;
|
|
|
|
while ($iptr >= 0 and $iptr < 0 + @instructions) {
|
|
$jump = @instructions[$iptr];
|
|
@instructions[$iptr]++;
|
|
$steps++;
|
|
|
|
$iptr += $jump
|
|
}
|
|
|
|
print $steps, "\n";
|
|
|
|
$iptr = 0;
|
|
$steps = 0;
|
|
|
|
while ($iptr >= 0 and $iptr < 0 + @instructions2) {
|
|
$jump = @instructions2[$iptr];
|
|
if ($jump >= 3) {
|
|
@instructions2[$iptr]--;
|
|
} else {
|
|
@instructions2[$iptr]++;
|
|
}
|
|
$steps++;
|
|
|
|
$iptr += $jump
|
|
}
|
|
print $steps, "\n";
|