diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-05-17 22:23:56 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-17 22:23:56 +0100 |
| commit | 3fe16b9a4867884e4cc5bf7170bc22cd9dd41a82 (patch) | |
| tree | d8de31ca21860e8b5b36257f6f4ddedccb6f9840 | |
| parent | 1be3cc268a99c8e93b404145df89b0e48bd7501a (diff) | |
| parent | f5a0d303bcf96a45ccc8db6bb9a8b3fec4d5add5 (diff) | |
| download | perlweeklychallenge-club-3fe16b9a4867884e4cc5bf7170bc22cd9dd41a82.tar.gz perlweeklychallenge-club-3fe16b9a4867884e4cc5bf7170bc22cd9dd41a82.tar.bz2 perlweeklychallenge-club-3fe16b9a4867884e4cc5bf7170bc22cd9dd41a82.zip | |
Merge pull request #6119 from adamcrussell/master
cleaned up code
| -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"; } |
