Solve day 05, in Perl.

This commit is contained in:
2017-12-05 09:53:30 +01:00
parent e165774dea
commit dcff672eeb
3 changed files with 1129 additions and 1 deletions

View File

@@ -18,7 +18,7 @@ The current plan, in no particular order:
- [ ] Kotlin - [ ] Kotlin
- [ ] Node.js - [ ] Node.js
- [ ] Objective C - [ ] Objective C
- [ ] Perl - [x] Perl - [Day 05](./day-05/solution.pl)
- [ ] PHP - [ ] PHP
- [ ] Prolog - [ ] Prolog
- [ ] Python - [ ] Python

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
View 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";