Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Coding puzzle 3
Message
From
06/06/2002 18:55:02
 
 
To
06/06/2002 14:56:09
Walter Meester
HoogkarspelNetherlands
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00665235
Message ID:
00665734
Views:
22
WOW Walter, it's 4 times faster than the routine I sent! I wonder whether we can use this routine to find the next unknown prime number!

>Hoi peter, Nadya
>
>>
>>create cursor prime ( primenumber i )
>>insert into prime value ( 3 )
>>
>>MaxRange = 100000
>>
>>t = seconds()
>>for i = 5 to MaxRange step 2
>>  if IsPrime(i)
>>	insert into prime value ( i )
>>  endif
>>next
>>? seconds() - t
>>
>>func isprime
>>	lpar i
>>	local n
>>	scan
>>		n = prime.primenumber
>>		if int( i / n ) = i / n
>>			return .f.
>>		endif
>>		if n^2 > i
>>			exit
>>		endif
>>	endscan
>>	return .t.
>>
>
>What about
>
>
>CREATE CURSOR Prime (primenumber i)
>INSERT INTO Prime VALUES (3)
>
>FOR I = 5 TO 100000 STEP 2
>	nSQRT = SQRT(i)
>	GO TOP
>	LOCATE WHILE prime.primenumber =< nSQRT FOR I % prime.primenumber = 0
>	IF !FOUND()
>		INSERT INTO Prime VALUES ( i )
>	ENDIF
>ENDFOR
>
>
>Long live the fast local data engine !! I wonder if VB can do this as fast as VFP.
>So the whole routine Nadya requested can look like the following:
>
>
>SET TALK OFF
>SELECT Numbers
>GO BOTTOM
>MaxRange = Numbers.Num
>
>** Generate Prime numbers
>
>CREATE CURSOR Prime (primenumber i)
>INSERT INTO Prime VALUES (3)
>
>FOR I = 5 TO MaxRange STEP 2
>	nSQRT = SQRT(i)
>	GO TOP
>	LOCATE WHILE prime.primenumber =< nSQRT FOR I % prime.primenumber = 0
>	IF !FOUND()
>		INSERT INTO Prime VALUES ( i )
>	ENDIF
>ENDFOR
>INDEX ON PrimeNumber TAG Prime
>
>** Determine the missing primenumbers in the gaps in the Numtable
>
>CREATE CURSOR Invert (un I)
>SELECT Numbers
>GO TOP
>
>nLow = Num
>SCAN
>	FOR nT = nLow+1 TO Num-1
>		IF KEYMATCH(nT,1,"Prime")
>			INSERT INTO Invert VALUES (nT)
>		ENDIF
>	ENDFOR
>	nLow=Num
>ENDSCAN
>
>
>Walter,
Groet,
Peter de Valença

Constructive frustration is the breeding ground of genius.
If there’s no willingness to moderate for the sake of good debate, then I have no willingness to debate at all.
Let's develop superb standards that will end the holy wars.
"There are three types of people: Alphas and Betas", said the beta decisively.
If you find this message rude or offensive or stupid, please take a step away from the keyboard and try to think calmly about an eventual a possible alternative explanation of my message.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform