mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Solve day 05, in Perl.
This commit is contained in:
1090
2017/day-05/input.txt
Normal file
1090
2017/day-05/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
38
2017/day-05/solution.pl
Executable file
38
2017/day-05/solution.pl
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/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";
|
||||
Reference in New Issue
Block a user