Daniel W. Posted April 13, 2006 Share Posted April 13, 2006 (edited) Hello, i wrote a programm that checks if a number is a prime number or not. $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 If you have ideas to improve it, just tell me Edited April 13, 2006 by Daniel W. --------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote] Link to comment Share on other sites More sharing options...
RazerM Posted April 13, 2006 Share Posted April 13, 2006 Hmmm i suppose its just a coincidence you posted this after i posted my prime number thing lol 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. Link to comment Share on other sites More sharing options...
Daniel W. Posted April 13, 2006 Author Share Posted April 13, 2006 Our codes do the same or? Cuz they are different in whole way --------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote] Link to comment Share on other sites More sharing options...
RazerM Posted April 13, 2006 Share Posted April 13, 2006 It appears that both our original ideas don't work. Try testing 529 (23*23) it says it is prime which it isn't as Wus told me in my thread. I have come up with this ;=============================================================================== ; ; 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 which works better but says 5 isnt prime (any ideas?) 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. Link to comment Share on other sites More sharing options...
Daniel W. Posted April 13, 2006 Author Share Posted April 13, 2006 (edited) I updated mine a bit for 529 and those numbers that havn't worked but dunno why yours is not working. Maybe because 5 is standart divisor?????? Just an idea Edited April 13, 2006 by Daniel W. --------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote] Link to comment Share on other sites More sharing options...
blindwig Posted April 13, 2006 Share Posted April 13, 2006 (edited) How about this: Func _IsPrime($iNum) $iNum=Abs($iNum) Local $iMax = $iNum, $iDiv = 2, $fDiv = 0 While Not $fDiv And $iDiv < $iMax $iMax = Int($iNum/$iDiv) $fDiv = $iMax = $iNum/$iDiv $iDiv += 1 WEnd Return $fDiv = 0 EndFunc Or, use the sqrt as RazorM did: Func _IsPrime($iNum) $iNum=Abs($iNum) Local $iMax = Sqrt($iNum) + 1, $iDiv = 2, $fDiv = 0, $iTemp While Not $fDiv And $iDiv < $iMax $iTemp = $iNum/$iDiv $fDiv = Int($iTemp) = $iTemp $iDiv += 1 WEnd Return $fDiv = 0 EndFunc Edited April 13, 2006 by blindwig My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now