Re: My vbScript answer to the Google Question. {the first 10 digit prime in e}.com



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.








.



Relevant Pages

  • Re: Primes in DNA (was: Definition Challenge)
    ... digit length in DNA found in earthly species. ... First twenty primes in binary: ... excluded from the last digit position forever and ever! ... there is no such list of quaternary primes in the genome ...
    (talk.origins)
  • Evidence For The Randomness Of Prime Numbers
    ... randomness of prime numbers based on the Last Digit Distribution. ... Aside from 2 and 5 there are no even primes or primes ending in the ... the last digit distribution as expressed by the Chi-square. ...
    (sci.math)
  • Re: Factoring
    ... We notice that the last digit of the multiplication of two prime ... And two odd numbers multiplied together must be odd. ... So for each number of the form P*Q where P and Q are primes, ... Then this excludes every one that is divisible by every other preceding ...
    (sci.math)
  • Re: Ask EU: Mathematical puzzle
    ... I have written down three 3-figure numbers which, overall, use no digit more than once. ... One of the numbers is a perfect square and the other two numbers are primes. ... must have the following combinations (forgetting for a moment about whether they combine to form primes in some way): ...
    (uk.media.radio.archers)
  • Re: Special primes
    ... | bischar wrote: ... If you were to consider two-digit primes, then what you are looking for are ... odd digit thingy. ...
    (sci.math)

Quantcast