aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Russell <ac.russell@live.com>2022-05-16 19:42:36 -0400
committerAdam Russell <ac.russell@live.com>2022-05-16 19:42:36 -0400
commitf5a0d303bcf96a45ccc8db6bb9a8b3fec4d5add5 (patch)
treebdcfe9e4779d5cad4c4b2e868cd17ba106ead49c
parentee76f708d44728731a2457531768c581cb65ef94 (diff)
downloadperlweeklychallenge-club-f5a0d303bcf96a45ccc8db6bb9a8b3fec4d5add5.tar.gz
perlweeklychallenge-club-f5a0d303bcf96a45ccc8db6bb9a8b3fec4d5add5.tar.bz2
perlweeklychallenge-club-f5a0d303bcf96a45ccc8db6bb9a8b3fec4d5add5.zip
cleaned up code
-rw-r--r--challenge-164/adam-russell/perl/ch-2.pl12
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";
}