Re: My vbScript answer to the Google Question. {the first 10 digit prime in e}.com
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 7 Sep 2007 08:07:04 -0500
I checked the code I posted on several computers, with versions of WSH from
5.1 to 5.7. The CDbl function works the same on them all. In your code you
have:
c=Mid(e,p,10)
....
r=CDbl(c)/CDbl(x)
which is exactly the same, the string c (a 10 digit string) is converted to
a double. The only difference is I made E a constant and you assigned the
string to a variable. Maybe try your assignment. Also, you can echo the
datatype of strType with:
MsgBox(TypeName(strTemp))
Also, you can check if it is numeric with:
MsgBox(IsNumeric(strTemp))
0 means false and -1 means true, so you should see -1. Otherwise, I'm
stumped.
I had to check my Knuth book "Seminumerical Algorithms" regarding the
Eratosthenes sieve. The text says you should be able to generate the array
with no multiplication. The implication is that longer code that avoids
multiplication will be more efficient. I'm sure there's a trade off. Also,
10 digit numbers are not very big. The sieve may not be faster until you are
dealing with much larger numbers.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
"Tim" <TimJordanVBS@xxxxxxxxxxx> wrote in message
news:1189160108.639652.318380@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi Richard,
thanks very much for the feedback. I niavely assumed that the fastest
code would be the smallest. I should have at least tried using Option
Explicit.... O well, I won't forget that tip in a hurry thanks!
That's interesting that using your 'imperfect' sequence of 'probable'
primes is faster than my method of using Eratosthenes sieve to
precalculate the actual primes.
I guess a lot depends upon where in E the first prime is, possibly if
it was very much further down (or if the question was 'find the
millionth 10 digit prime in e'), then my method might catch up (using
Option Explicit of course!).
One annoying thing which means I can't actually run your code, is that
I keep getting a type mismatch error on this line:
dblCandidate = CDbl(Mid(E, k, 10))
Iv'e tried:
strTemp = Mid(E, k, 10)
dblCandidate = CDbl(strTemp)
but I still get the type mismatch.
I have also done
MsgBox strTmp
Just to confirm it really looks like a 10 digit number (and it does).
I've come accross a oddities like this before where vbScript code
that's happy on one machine gives type mismatches on another...
Any clues as to why?
Tim.
.
- Follow-Ups:
- References:
- My vbScript answer to the Google Question. {the first 10 digit prime in e}.com
- From: Tim
- Re: My vbScript answer to the Google Question. {the first 10 digit prime in e}.com
- From: Richard Mueller [MVP]
- Re: My vbScript answer to the Google Question. {the first 10 digit prime in e}.com
- From: Richard Mueller [MVP]
- Re: My vbScript answer to the Google Question. {the first 10 digit prime in e}.com
- From: Richard Mueller [MVP]
- Re: My vbScript answer to the Google Question. {the first 10 digit prime in e}.com
- From: Tim
- My vbScript answer to the Google Question. {the first 10 digit prime in e}.com
- Prev by Date: Re: HTA to hyperlink to Notepad
- Next by Date: Re: Connect to AD from stand-alone computer
- Previous by thread: Re: My vbScript answer to the Google Question. {the first 10 digit prime in e}.com
- Next by thread: Re: My vbScript answer to the Google Question. {the first 10 digit prime in e}.com
- Index(es):
Relevant Pages
|