Verification for finding prime numbers

3 posts in this topic

#1 ·  Posted (edited)

I can not for the life of me get this to work, the script finds prime numbers just fine and logs them in a nice way, but I can not get it to reject text, negative numbers and/or numbers with a decimal point. Here's what I have so far, it just opens the input box in an infinite loop no matter what I type in. The verification is in the first 'Do' loop.

$okpass = 0
$number = 1
$limit = InputBox( "the limit", "what would you lke to make the limit?")
$errtest = IsNumber($limit) + IsInt($limit)
   $isnumber = IsNumber($limit)
   $isint = IsInt($limit)
   If $isnumber == 0 Or $isint == 0 or $limit <= 0 Then
      $limit = InputBox( "the limit", "please input a valid integer. Letters, numbers with decimal places and negative numbers will not work!")
      $okpass = 1

Until $okpass == 1

   Do ; resets everything each time the number is increased
         $number += 1
         $tempnum = 1
         $no = 0
         $next = 0
   Until $number >= $limit

   Func isprime() ; checks to see if the variable is a prime number using a loop
      If $number > 3 then
            $tempnum += 1
            $test = $number / $tempnum
            If IsInt ( $test ) Then
               $no = 1
               $next += 1

            If $next >= ($number / 2) Then
               FileWrite(@ScriptDir & "primenumbers.txt", $number & ", ")
               $no = 1
         Until $no == 1
      FileWrite(@ScriptDir & "primenumbers.txt", $number & ", ")


Edited by itsnotluketime

Share this post

Link to post
Share on other sites

#3 ·  Posted (edited)

The greatest with AutoIt findable prime using a Array for solving  (limitation of Array) without using any UDF is 16777213. There are 1077870 smaller primes in this range. Found with a AutoItscript < 290 sec.

Attached contains textfile with the primes and DemoPrimes.exe,  AV-Test: SHA256:1267ddf7cc6a0a7bb0a7b6e064242fe452ddefd936a3f0adcea6ee761b830fa4


The func i used is the only one in a UDF i was Co-Author.

Edited by AutoBert

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now