mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Clean up day 5.
This commit is contained in:
@@ -1,19 +1,23 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
my @instructions;
|
my @instructions;
|
||||||
|
|
||||||
for $line ( <STDIN> ) {
|
for my $line ( <STDIN> ) {
|
||||||
push @instructions, $line;
|
push @instructions, $line;
|
||||||
}
|
}
|
||||||
|
|
||||||
@instructions2 = @instructions;
|
my @instructions2 = @instructions;
|
||||||
|
|
||||||
$iptr = 0;
|
my $iptr = 0;
|
||||||
|
|
||||||
$steps = 0;
|
my $steps = 0;
|
||||||
|
|
||||||
while ($iptr >= 0 and $iptr < 0 + @instructions) {
|
while ($iptr >= 0 and $iptr < @instructions) {
|
||||||
$jump = @instructions[$iptr];
|
my $jump = $instructions[$iptr];
|
||||||
@instructions[$iptr]++;
|
$instructions[$iptr]++;
|
||||||
$steps++;
|
$steps++;
|
||||||
|
|
||||||
$iptr += $jump
|
$iptr += $jump
|
||||||
@@ -24,12 +28,12 @@ print $steps, "\n";
|
|||||||
$iptr = 0;
|
$iptr = 0;
|
||||||
$steps = 0;
|
$steps = 0;
|
||||||
|
|
||||||
while ($iptr >= 0 and $iptr < 0 + @instructions2) {
|
while ($iptr >= 0 and $iptr < @instructions2) {
|
||||||
$jump = @instructions2[$iptr];
|
my $jump = $instructions2[$iptr];
|
||||||
if ($jump >= 3) {
|
if ($jump >= 3) {
|
||||||
@instructions2[$iptr]--;
|
$instructions2[$iptr]--;
|
||||||
} else {
|
} else {
|
||||||
@instructions2[$iptr]++;
|
$instructions2[$iptr]++;
|
||||||
}
|
}
|
||||||
$steps++;
|
$steps++;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user