Paulie Posted September 29, 2007 Posted September 29, 2007 (edited) I just "Stumbled Upon" this Regular Expression that seems to be able to tell if a number is prime.I piped it into autoit, and it seems to work!Unfortunately, due to my limited knowledge of StringRegExp, I find myself unable to understand exactly how it works, and i was wondering if one of the RegExp Gurus here could give me an explanation of the logic behind it.Func _IsPrime($Integer) $String = "" For $i = 1 to Number($Integer) $String&="1" Next If Not StringRegExp($String,"^1?$|^(11+?)\1+$") Then Return 1 Else Return 0 EndIf EndFunc Edited September 29, 2007 by Paulie
Paulie Posted September 29, 2007 Author Posted September 29, 2007 I have a feeling that i have managed to fugure at least the vast majority of this one out by myself. Now that i understand the concept of "Backtracking" it all makes sense. Thanks
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