From 5b53308a8db4d4d589fdd08f113e466dd084e78a Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Wed, 6 Dec 2017 12:27:03 +0100 Subject: [PATCH] Clean up day 5. --- 2017/day-05/solution.pl | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/2017/day-05/solution.pl b/2017/day-05/solution.pl index 60dd385..2a8ee7b 100755 --- a/2017/day-05/solution.pl +++ b/2017/day-05/solution.pl @@ -1,19 +1,23 @@ #!/usr/bin/perl + +use strict; +use warnings; + my @instructions; -for $line ( ) { +for my $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) { - $jump = @instructions[$iptr]; - @instructions[$iptr]++; +while ($iptr >= 0 and $iptr < @instructions) { + my $jump = $instructions[$iptr]; + $instructions[$iptr]++; $steps++; $iptr += $jump @@ -24,12 +28,12 @@ print $steps, "\n"; $iptr = 0; $steps = 0; -while ($iptr >= 0 and $iptr < 0 + @instructions2) { - $jump = @instructions2[$iptr]; +while ($iptr >= 0 and $iptr < @instructions2) { + my $jump = $instructions2[$iptr]; if ($jump >= 3) { - @instructions2[$iptr]--; + $instructions2[$iptr]--; } else { - @instructions2[$iptr]++; + $instructions2[$iptr]++; } $steps++;