diff options
| -rw-r--r-- | challenge-164/adam-russell/perl/ch-2.pl | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/challenge-164/adam-russell/perl/ch-2.pl b/challenge-164/adam-russell/perl/ch-2.pl index 356b738b68..39c323cbab 100644 --- a/challenge-164/adam-russell/perl/ch-2.pl +++ b/challenge-164/adam-russell/perl/ch-2.pl @@ -1,7 +1,7 @@ use strict; use warnings; ## -# W +# Write a script to find the first 8 Happy Numbers in base 10. ## use boolean; use constant N => 8; @@ -10,12 +10,12 @@ sub happy{ my $n = shift; my @seen; my $pdi = sub{ - my $x = shift; + my $n = shift; my $total = 0; { - $total += ($x % 10)**2; - $x = int($x / 10); - redo if $x > 0; + $total += ($n % 10)**2; + $n = int($n / 10); + redo if $n > 0; } return $total; }; @@ -33,7 +33,7 @@ MAIN:{ { $i++; push @happy, $i if happy($i); - redo if @happy < 8; + redo if @happy < N; } print join(", ", @happy) . "\n"; } |
