利用正则判别素数,来源于网络,神人!
Set regex = New RegExp
regex.Pattern = "^1?$¦^(11+?)\1+$"
For i = 1 To 100
If Not regex.Test(String(i,"1")) Then
WScript.Echo i
End If
Next
看到标题你一定会不屑一顾,枚举质数谁不会?
For i = 1 To 100
For j = 2 To i
If i Mod j = 0 Then Exit For
Next
If j = i Then WScript.Echo i
Next
几行代码就能搞定,如此简单。那就看看下面这个程序吧!
Set regex = New RegExp
regex.Pattern = "^1?$|^(11+?)\1+$"
For i = 1 To 100
If Not regex.Test(String(i,"1")) Then
WScript.Echo i
End If
Next
用正则表达式判断质数,神一样的人物。
来源:
http://demon.tw/programming/vbs-prime-number.html
http://www.enun.net/?p=533