aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-04-04 19:59:01 +0100
committerdrbaggy <js5@sanger.ac.uk>2022-04-04 19:59:01 +0100
commite0ccb368c09d324df30fb8581b95bfda6bd5011f (patch)
tree33baf6987248c2e7c0d50dc6f64aaccd60fb7c07
parentd0335bccd0294b93ca8539b22390c0064baa3193 (diff)
downloadperlweeklychallenge-club-e0ccb368c09d324df30fb8581b95bfda6bd5011f.tar.gz
perlweeklychallenge-club-e0ccb368c09d324df30fb8581b95bfda6bd5011f.tar.bz2
perlweeklychallenge-club-e0ccb368c09d324df30fb8581b95bfda6bd5011f.zip
another tweak
-rw-r--r--challenge-159/james-smith/perl/ch-2.pl5
1 files changed, 3 insertions, 2 deletions
diff --git a/challenge-159/james-smith/perl/ch-2.pl b/challenge-159/james-smith/perl/ch-2.pl
index 7d22c8df6d..fb9ee8a893 100644
--- a/challenge-159/james-smith/perl/ch-2.pl
+++ b/challenge-159/james-smith/perl/ch-2.pl
@@ -32,7 +32,8 @@ warn "exp";
is( moebius_exp( $_->[0] ), $_->[1] ) for @TESTS;
warn "opt";
is( moebius_div_opt( $_->[0] ), $_->[1] ) for @TESTS;
-timethis( 500_000, sub { moebius_div_opt( $_->[0] ) for @TESTS } );
+#timethis( 500_000, sub { moebius_div_opt( $_->[0] ) for @TESTS } );
+exit;
warn "div";
is( moebius_div( $_->[0] ), $_->[1] ) for @TESTS;
timethis( 100, sub { moebius_div( $_->[0] ) for @TESTS } );
@@ -59,7 +60,7 @@ sub moebius_div {
sub moebius_div_opt {
my ($n,$p,$r) = (shift,1,1);
return -1 if is_prime $n;
- $n%$p || ($r=-$r,$n/=$p) && ( $n%$p ? ( (is_prime $n) && (return -$r) ) : return 0 ) while ($p = next_prime $p)**2 <= $n;
+ $n%$p || ($n/=$p) && $n%$p ? ( is_prime $n ? (return $r) : ($r=-$r) ) : return 0 while ($p = next_prime $p)**2 <= $n;
$r;
}