diff options
| author | drbaggy <js5@sanger.ac.uk> | 2022-02-23 12:14:22 +0000 |
|---|---|---|
| committer | drbaggy <js5@sanger.ac.uk> | 2022-02-23 12:14:22 +0000 |
| commit | 8068626532b4f51027229a7e3910bc753f7dfc3f (patch) | |
| tree | 6c324bb8697c25b7e5875f3c3b5e9994e4c5268e | |
| parent | 1f0b1bb7c4547e1a90c6a9e5e3e917896cec09f7 (diff) | |
| download | perlweeklychallenge-club-8068626532b4f51027229a7e3910bc753f7dfc3f.tar.gz perlweeklychallenge-club-8068626532b4f51027229a7e3910bc753f7dfc3f.tar.bz2 perlweeklychallenge-club-8068626532b4f51027229a7e3910bc753f7dfc3f.zip | |
added note about upper limit of factorions
| -rw-r--r-- | challenge-153/james-smith/perl/ch-2.pl | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/challenge-153/james-smith/perl/ch-2.pl b/challenge-153/james-smith/perl/ch-2.pl index 0eb21c81ef..457b3cbd80 100644 --- a/challenge-153/james-smith/perl/ch-2.pl +++ b/challenge-153/james-smith/perl/ch-2.pl @@ -15,11 +15,19 @@ my @TESTS = ( [ 145, 1 ], [ 125, 0 ], ); is( is_factorion($_->[0])||0, $_->[1] ) foreach @TESTS; done_testing(); +## Has to be at most 7 digits as 8x9! < 9_999_999 +## We note that 8x9^7 is the maximum possible value +## Further the value of this is 2_540_160. So we note +## that the maxium value is 2 + 6*9! or 2_177_282. +## +## So we are guaranteed to find all values if we +## search as far as this value... + is_factorion($_) && say for 1 .. 2_177_282; sub is_factorion { my $t = $_[0]; - $t-=$f[$_] for split //,$_[0]; - !$t; + ($t-=$f[$_])||return 1 for split //,$t; + return 0; } |
