Jump to content



Photo

_isprime Function


  • Please log in to reply
37 replies to this topic

#1 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 13 April 2006 - 01:05 PM

I made a function to see if a number is prime or not. I was bored This has been updated and the function below does work
AutoIt         
;=============================================================================== ; ; Function Name:   _IsPrime ; Description:: Check if a number is prime or not ; Parameter(s): $i_num - Number to check ; Requirement(s):  None ; Return Value(s): 1 - Number is prime ;                 0 - Number is not prime ;                  -1 - String isn't a number ; Author(s):       RazerM ; ;=============================================================================== ; Func _IsPrime($i_num)     If StringIsDigit($i_num) = 0 Then Return -1     If $i_num > 3 Then         If Mod($i_num, 2) = 0 Then Return 0         If Mod($i_num, 3) = 0 Then Return 0     EndIf     If $i_num = 1 Then Return 0     Dim $divisor, $increment, $maxdivisor     $divisor = 5     $increment = 2     $maxdivisor = Sqrt($i_num) + 1         Do         If Mod($i_num, $divisor) = 0 And $i_num <> $divisor Then Return 0         $divisor = $divisor + $increment         $increment = 6 - $increment     Until $divisor > $maxdivisor     Return 1 EndFunc ;==>_IsPrime


Edit: updated to most recent code

Edited by RazerM, 19 May 2006 - 03:30 PM.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.





#2 VicTT

VicTT

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 379 posts

Posted 13 April 2006 - 01:54 PM

There is an infinity of factors to be checked before concluding that a number is prime or not(This can be proven)...Your script is incomplete and thus, useless for any prime number higher or equal to 23...Post_Number++;

Together we might liveDivided we must fall


#3 Wus

Wus

    Indentured Servant

  • Active Members
  • PipPipPipPipPipPip
  • 513 posts

Posted 13 April 2006 - 02:10 PM

I fail to see how this function would work.
You are trying to test for primeness based on a finite set of primes. But seeing as how there are infinite primes that wont work. All I had to do to fool your algorithm was to take the next prime after 19 and square it.

ie:
your function tells me that (23*23) or 529 is prime when its obviously the product of two integers.

Prime tests usually have to test the majority of the values from from i=2 to i=int(sqrt(testVal)) +1 for divisability.

This can be seen here http://www.devx.com/vb2themax/Tip/19051
Posted Image

#4 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 13 April 2006 - 03:41 PM

thanks for the feedback guys. Based on that site Wus i made this
Plain Text         
;=============================================================================== ; ; Function Name:   _IsPrime ; Description:: Check if a number is prime or not ; Parameter(s): $i_num - Number to check ; Requirement(s):  Math.au3 ; Return Value(s): 1 - Number is prime ;                  0 - Number is not prime ; Author(s):       RazerM ; ;=============================================================================== ; Func _IsPrime($i_num)     If $i_num > 3 Then         If Mod($i_num, 2) = 0 Then Return 0         If Mod($i_num, 3) = 0 Then Return 0     EndIf     Dim $divisor, $increment, $maxdivisor     $divisor = 5     $increment = 2     $maxdivisor = Sqrt($i_num) + 1     Do         If Mod($i_num, $divisor) = 0 Then Return 0         $divisor = $divisor + $increment         $increment = 6 - $increment     Until $divisor > $maxdivisor     Return 1 EndFunc
It appears to work but it returns 0 when i test 5 and 5 is definetely prime
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

#5 Daniel W.

Daniel W.

    I hacked 127.0.0.1 !!!

  • Active Members
  • PipPipPipPipPipPip
  • 434 posts

Posted 13 April 2006 - 03:49 PM

Maybe because your Divisor is 5?
I dont know because for me your code is very difficult to understand ( i am newbie atm :think:)
--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------

Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.


#6 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 13 April 2006 - 03:53 PM

Thanks, thats it!
Plain Text         
;=============================================================================== ; ; Function Name:   _IsPrime ; Description:: Check if a number is prime or not ; Parameter(s): $i_num - Number to check ; Requirement(s):  None ; Return Value(s): 1 - Number is prime ;                  0 - Number is not prime ; Author(s):       RazerM ; ;=============================================================================== ; Func _IsPrime($i_num)     If $i_num > 3 Then         If Mod($i_num, 2) = 0 Then Return 0         If Mod($i_num, 3) = 0 Then Return 0     EndIf     Dim $divisor, $increment, $maxdivisor     $divisor = 5     $increment = 2     $maxdivisor = Sqrt($i_num) + 1         Do         If Mod($i_num, $divisor) = 0 And $i_num <> $divisor Then Return 0         $divisor = $divisor + $increment         $increment = 6 - $increment     Until $divisor > $maxdivisor     Return 1 EndFunc  ;==>_IsPrime


I removed the Math.au3 in requirement and made sure it checked whether the number and the divisor were the same or not before returning 0
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

#7 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 13 April 2006 - 04:10 PM

if you use ConsoleWrite on $increment you will see it alternates between 2 and 4 like it is meant to.

I have updated mine to return 0 if the number is 1
Plain Text         
;=============================================================================== ; ; Function Name:   _IsPrime ; Description:: Check if a number is prime or not ; Parameter(s): $i_num - Number to check ; Requirement(s):  None ; Return Value(s): 1 - Number is prime ;                  0 - Number is not prime ; Author(s):       RazerM ; ;=============================================================================== ; Func _IsPrime($i_num)     If $i_num > 3 Then         If Mod($i_num, 2) = 0 Then Return 0         If Mod($i_num, 3) = 0 Then Return 0         EndIf     If $i_num = 1 Then Return 0     Dim $divisor, $increment, $maxdivisor     $divisor = 5     $increment = 2     $maxdivisor = Sqrt($i_num) + 1         Do         If Mod($i_num, $divisor) = 0 And $i_num <> $divisor Then Return 0         $divisor = $divisor + $increment         $increment = 6 - Abs($increment)     Until $divisor > $maxdivisor     Return 1 EndFunc  ;==>_IsPrime

Edited by RazerM, 13 April 2006 - 04:13 PM.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

#8 Daniel W.

Daniel W.

    I hacked 127.0.0.1 !!!

  • Active Members
  • PipPipPipPipPipPip
  • 434 posts

Posted 13 April 2006 - 04:13 PM

Plain Text         
$zahl = InputBox("Zahl angeben", "Geben Sie an welche Zahl zu überprüfen ist.")             If $zahl = 3 Then             MsgBox(0, "", "Primzahl")             ElseIf $zahl = 5 Then             MsgBox(0, "", "Primzahl")             ElseIf $zahl = 7 Then             MsgBox(0, "", "Primzahl")             ElseIf $zahl = 529 Then             MsgBox(0,"", "Keine Primzahl")             Else             $I_Result = _MathCheckDiv($zahl, 2)             If $I_Result = 2 Then                MsgBox(0,'','Keine Primzahl')             Else                $I_Result = _MathCheckDiv($zahl, 3)                If $I_Result = 2 Then             Msgbox(0, "", "Keine Primzahl")                Else                $I_Result = _MathCheckDiv($zahl, 5)                If $I_Result = 2 Then             Msgbox(0, "", "Keine Primzahl")                Else             $I_Result = _MathCheckDiv($zahl, 7)                If $I_Result = 2 Then             Msgbox(0, "", "Keine Primzahl")             Else             Msgbox(0, "", "Primzahl")             EndIf             EndIf             EndIf             EndIf             EndIf

Hmm kk razerM and Wus
I am newbie atm so thats just the beginning of my autoIT programms maybe i get better later :think:
Msgboxes are in German cuz i am from Germany dont wonder so ^^

Edited by Daniel W., 13 April 2006 - 04:17 PM.

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------

Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.


#9 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 13 April 2006 - 04:15 PM

it doesnt work, Daniel W. You need to consider a lot more factors. try and understand what is in my script or Larry's
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

#10 Wus

Wus

    Indentured Servant

  • Active Members
  • PipPipPipPipPipPip
  • 513 posts

Posted 13 April 2006 - 04:16 PM

Mine should :think: be working completly, if you find an error in it. Tell me
Msgboxes are in German cuz i am from Germany dont wonder so ^^


The problem is that your testing your input against a finite set of known primes, this cannot work since there are infinite primes. You cant use that apporach.
Posted Image

#11 Confuzzled

Confuzzled

    Mouse moved. Please restart Windows for changes to take effect.

  • Active Members
  • PipPipPipPipPipPip
  • 1,000 posts

Posted 13 April 2006 - 06:18 PM

You code works, but the algorithm is flawed.

#12 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 13 April 2006 - 07:26 PM

You code works, but the algorithm is flawed.

My code or Daniels code?
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

#13 greenmachine

greenmachine

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,252 posts

Posted 13 April 2006 - 11:45 PM

Mine is more along the lines of Larry's, but it does fewer because it only goes to the sqrt of the inputted number instead of half (sqrt is the correct middle). It returns an array with the prime status at [0], the first divisor at [1], and the result of the division at [2].
Plain Text         
$prime = _checkforprime (236993) If Not @error Then     _ArrayDisplay ($prime, "prime") EndIf Func _checkforprime($numcheck)     Local $divisor[3]     If Not IsInt ($numcheck) Then         SetError (1)         Return -1     EndIf     If Mod ($numcheck, 2) = 0 Then         $divisor[0] = 0         $divisor[1] = 2         $divisor[2] = $numcheck/2         Return $divisor     EndIf     For $i = 3 To Int (Sqrt ($numcheck)) + 1 Step 2         If Mod ($numcheck, $i) = 0 Then             $divisor[0] = 0             $divisor[1] = $i             $divisor[2] = $numcheck/$i             Return $divisor         EndIf     Next     $divisor[0] = 1     $divisor[1] = 1     $divisor[2] = $numcheck     Return $divisor EndFunc


#14 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 14 April 2006 - 05:22 PM

ive added another check to mine
Plain Text         
;=============================================================================== ; ; Function Name:   _IsPrime ; Description:: Check if a number is prime or not ; Parameter(s): $i_num - Number to check ; Requirement(s):  None ; Return Value(s): 1 - Number is prime ;                 0 - Number is not prime ;                  -1 - String isn't a number ; Author(s):       RazerM ; ;=============================================================================== ; Func _IsPrime($i_num)     If StringIsDigit($i_num) = 0 Then Return -1     If $i_num > 3 Then         If Mod($i_num, 2) = 0 Then Return 0         If Mod($i_num, 3) = 0 Then Return 0     EndIf     If $i_num = 1 Then Return 0     Dim $divisor, $increment, $maxdivisor     $divisor = 5     $increment = 2     $maxdivisor = Sqrt($i_num) + 1         Do         If Mod($i_num, $divisor) = 0 And $i_num <> $divisor Then Return 0         $divisor = $divisor + $increment         $increment = 6 - $increment     Until $divisor > $maxdivisor     Return 1 EndFunc ;==>_IsPrime

Edited by RazerM, 21 April 2006 - 03:39 PM.

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

#15 GrungeRocker

GrungeRocker

    *narF*

  • Active Members
  • PipPipPipPipPipPip
  • 422 posts

Posted 14 April 2006 - 08:16 PM

why do you need to check if a number is a prime?

EDIT1:
well i search for an old cpp example of this :think:

EDIT2:
ok its not the same, but here you are (its in c++)
Plain Text         
#include <iostream> using namespace std; int main(){ int anfang, ende; int anzprim = 0; cout<<"Calc Primenumbers from:"; cin>>anfang; cout<<"to:"; cin>>ende; if (anfang < 2) anfang = 2; for (int zahl = anfang; zahl <= ende; ++zahl){ int anzteiler = 0; int teiler = 2 while((anzteiler == 0 ) && (teiler < zahl)){ if (zahl % teiler == 0)//zahl is not a prime anzteiler++; teiler++; } if (anzteiler == 0){//zahl is a prime cout<<zahl<<""; anzprim++; } } cout<<endl<<anzprim<<" primenumbers were found."<<endl; return 0; }

Edited by GrungeRocker, 14 April 2006 - 08:49 PM.

In work:

#16 Dethredic

Dethredic

    http://gunnewiek.com/

  • Active Members
  • PipPipPipPipPipPip
  • 2,029 posts

Posted 17 September 2006 - 02:34 PM

I tried your script but nothing happened?!?!?

Y is this

there was no error or anything

it ran and was done in a second

Help!!!
Posted Image"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

#17 RazerM

RazerM

    cowinkeedenky - coincidence?

  • Active Members
  • PipPipPipPipPipPip
  • 1,246 posts

Posted 17 September 2006 - 03:20 PM

If you are referring to my script then it is only a function. You need to call it like this:

_IsPrime($n)

where $n can be any number
My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.

#18 jaenster

jaenster

    There is no spoon.

  • Active Members
  • PipPipPipPipPipPip
  • 670 posts

Posted 18 September 2006 - 09:15 AM

;Teh thing by jaenster func omfg($lol) if $lol/2 = round($i/2) then  return 1 endif return 0 endfunc

-jaenster

#19 Dethredic

Dethredic

    http://gunnewiek.com/

  • Active Members
  • PipPipPipPipPipPip
  • 2,029 posts

Posted 18 September 2006 - 02:52 PM

I have:


#include <GuiConstants.au3>

GuiCreate("Prime Finder", 316, 111,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Button_1 = GuiCtrlCreateButton("Is It Prime?", 60, 60, 190, 30)
$Input_2 = GuiCtrlCreateInput("", 10, 20, 300, 30)

GuiSetState()
While 1
$msg = GuiGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button_1
;read the input box here then find out if it is prime.
;if it is prime the msgbox" the number is prime
;if it isn't prime then msgbox the number is not prime
EndSelect
WEnd


how can i do this part useing your function

;read the input box here then find out if it is prime.
;if it is prime the msgbox" the number is prime
;if it isn't prime then msgbox the number is not
Posted Image"Its not about the 30 inch 1080p display, or the SLI 8800 ultras, or the DDR3 memory. It's about when you turn on your PC, does it return the favor?"Math is like sex. Sure, it may give some practical results, but that is not why we do it

#20 Manadar

Manadar

    Taking a REST.

  • MVPs
  • 10,714 posts

Posted 18 September 2006 - 04:01 PM

Here's a funny checker: I only translated Eratosthenes function from some language to AutoIt.

AutoIt         
$prime = Eratosthenes(50000) For $x = 0 to UBound($prime)-1     ToolTip("Now checking: " & $x & " prime: " & $prime[$x], 0, 0)     If LarryPrime($x) <> $prime[$x] Then         MsgBox(0, @ScriptName, "LarryPrime is flawed, at number: " & $x)     EndIf     If _IsPrime($x) <> $prime[$x] Then         MsgBox(0, @ScriptName, "_IsPrime is flawed, at number: " & $x)     EndIf Next Func Eratosthenes($n)     Dim $a[$n+1]     For $i = 0 to 1         $a[$i] = 0     Next     For $i = 2 to $n         $a[$i] = 1     Next     Dim $p = 2     While $p^2 < $n+1         $j = $p^2         While $j < $n+1             $a[$j] = 0             $j = $j + $p         WEnd         Do             $p += 1         Until $a[$p] = 1     WEnd     Return $a EndFunc Func LarryPrime($number)     Local $DaNum     $DaNum = Abs($number)     If $DaNum < 2 And $DaNum > -2 Then Return 1     For $n = 2 to Int(($DaNum/2) + 1)         If Mod($DaNum,$n) = 0 Then Return 0     Next     Return 1 EndFunc Func _IsPrime($i_num)     If $i_num > 3 Then         If Mod($i_num, 2) = 0 Then Return 0         If Mod($i_num, 3) = 0 Then Return 0         EndIf     If $i_num = 1 Then Return 0     Dim $divisor, $increment, $maxdivisor     $divisor = 5     $increment = 2     $maxdivisor = Sqrt($i_num) + 1         Do         If Mod($i_num, $divisor) = 0 And $i_num <> $divisor Then Return 0         $divisor = $divisor + $increment         $increment = 6 - Abs($increment)     Until $divisor > $maxdivisor     Return 1 EndFunc  ;==>_IsPrime


Edit: If someone has the CPU power and time to run it up to 100000 please do! And tell me some of the results. :)

Edited by Manadar, 18 September 2006 - 04:49 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users