use strict; # use Stream; use Math::Pari qw(gcd); # We can test all the factors at once using the greatest common divisor algorithm. my @factors = @ARGV; my \$test_number = 1; \$test_number *= \$_ for @factors; die "Must provide a list of non-zero factors\n" unless \$test_number > 1; sub has_common_factor { gcd(\$_[0], \$test_number) != 1 } # my \$integers = Stream::tabulate( sub { \$_[0] }, 1); # my \$challenge = \$integers->filter(\&has_common_factor); # \$challenge->show(50); print "@{[grep has_common_factor(\$_), 1..50]}\n"; ##```## sub tail { my \$t = \$_[0]{t}; if (ref \$t eq CODE) { # It is a promise \$_[0]{t} = &\$t; # <--- there! } \$_[0]{t}; } ##``````## R: number of primes in the input c1: number of times merge was called c2: number of times a < comparison was executed in merge c3: time factor predicted by formula r1: c1/c3 r2: c2/c3 R c1 c2 c3 r1 r2 2 2002 3002 1667 1.201 1.801 3 3276 5095 4133 0.793 1.233 4 4227 6821 7057 0.599 0.967 5 4989 8203 10137 0.492 0.809 6 5673 9534 13440 0.422 0.709 7 6303 10744 16834 0.374 0.638 8 6921 11966 20377 0.340 0.587 9 7499 13098 23983 0.313 0.546 10 8015 14108 27602 0.290 0.511 11 8538 15149 31314 0.273 0.484 12 9025 16107 35040 0.258 0.460 ```