in reply to A natural occurrence
use Math::BigFloat; use strict; use warnings; Math::BigFloat->accuracy(400); # the length of the prime to find in e my $prime_length = $ARGV[0] || 10; # build e (1/0! + 1/1! + 1/2! + 1/3! + ... + 1/125!) my $e = do { my $t = Math::BigFloat->new; $t += 1/Math::BigFloat->new($_)->bfac for 0..125; $t->bstr }; # grab substrings for (0 .. length($e) - $prime_length) { my $potential = substr $e, $_, $prime_length; print "found prime $potential \@ position $_\n" and last if is_prime($potential); } sub is_prime { my ($p) = @_; $p % $_ == 0 and return for 2, 3 .. sqrt($p); # 2, 3 .. sqrt($p) is + my trick return 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: A natural occurrence
by davido (Cardinal) on Mar 01, 2006 at 20:41 UTC | |
|
Re^2: A natural occurrence
by jdalbec (Deacon) on Mar 04, 2006 at 16:03 UTC | |
by japhy (Canon) on Mar 04, 2006 at 21:57 UTC |