Sign in to follow this  
Followers 0
ezzetabi

Looking for Prime Numbers?

6 posts in this topic

#1 ·  Posted (edited)

Pretty useless, but fun script for calculate prime numbers until a you limit you want.

;Better code below.
Edited by ezzetabi

Share this post


Link to post
Share on other sites



I think that would be useful for my little brother. Let me copy + paste that really quick =)

Share this post


Link to post
Share on other sites

Thanks to a CyberSlug idea and a my idea we have a much faster version!

Dim $PRIMI[2], $N = 1, $C, $T = 0, $L, $LIMIT, $PATH
$LIMIT = 5000
$PATH = 'c:\primi.txt'

If $LIMIT < 2 Then Exit
$PRIMI[0] = 1
$PRIMI[1] = 2
$FILE = FileOpen($PATH, 2)
If $FILE = -1 Then Exit

FileWrite($FILE, '2' & @CRLF);It adds 2 to the file since it is already in the array as begin of all.
HotKeySet('!x', '_Terminate')

While 1
   $N = $N + 2;It skips all divisible by 2 numbers. The 2 is already added as begin.
              ;since they can't be prime.
   $T = 0
   If $N >= $LIMIT Then Exit
   For $C = 1 To $PRIMI[0]
      If $PRIMI[$C] > Sqrt($N) Then ExitLoop;It avoids useless controls
      If Mod($N, $PRIMI[$C]) = 0 Then
         $T = 1
         ExitLoop
      EndIf
   Next
   
   If $T = 0 Then
      $L = UBound($PRIMI)
      ReDim $PRIMI[$L + 1]
      $PRIMI[0] = $L
      $PRIMI[$L] = $N
      FileWrite($FILE, $PRIMI[$PRIMI[0]] & @CRLF)
      ToolTip($PRIMI[$PRIMI[0]])
   EndIf
Wend


Exit
Func _Terminate()
   FileClose($FILE)
   Exit
EndFunc  ;==>_Terminate

Share this post


Link to post
Share on other sites

If you really are looking for prime numbers, You can use Prime95 from here: http://www.mersenne.org/freesoft.htm

That is, unless the novelty of this script is not the fact that it finds prime numbers, but that it finds those numbers using autoit.


Who else would I be?

Share this post


Link to post
Share on other sites

I never said I made somthing new. Also for serious password cracking the limit of Autoit variables is too strict. I made this just for fun.

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
Sign in to follow this  
Followers 0