This little script just searches for prime numbers. It outputs the found prime numbers to one file and the progress of it's searching to another. It was just fun to write, and i pushed the results through some numbercrunching modules on CPAN just so I could have the joy of finding no lasting pattern for myself. ;o)
use strict; use Math::BigInt; open(OUT, ">", "C:\\Devel\\Fun\\MathFun\\search.txt") or die "No output file"; open(ANS, ">", "C:\\Devel\\Fun\\MathFun\\primes.txt") or die "No primes file"; my @primes = (Math::BigInt->new(2), Math::BigInt->new(3), Math::BigInt->new(5), Math::BigInt->new(7)); print "Enter value to search to: "; my $max = <STDIN>; chop($max); my $x = Math::BigInt->new(10); for($x; $x < $max; $x++) { my $is = 1; foreach my $prime (@primes) { my $diff = $x->bmod($prime); $diff = chop($diff); print OUT "\t$prime\t$diff\n"; if ($diff == 0) { $is = 0; last; } } if ($is) { my $y = Math::BigInt->new($x); push(@primes, $y); print OUT "\t\t\t\tPrime:\t$y\n"; print "Prime:\t$y\n"; } print OUT "\n"; } foreach my $prime (@primes) { my $prime = substr($prime,1); print ANS "$prime\n"; }

In reply to Finding Primes by Fideist11

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.