Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Coding puzzle 3
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00665235
Message ID:
00665409
Views:
20
Hi Sergey,

You're the fastest and gave the completely SQL solution. I guess, we now have to measure the speed comparing with SCAN solution.

>Assuming, that it's Sql Server table 'testun' with one field 'un int'. :)
SELECT t1.un+1 AS uns,
>		(SELECT MIN(t3.un-1) FROM testun t3 WHERE t3.un-1 >= t1.un+1) AS une
>	FROM testun t1
>	WHERE NOT EXISTS (SELECT * FROM testun t2 WHERE t2.un = (t1.un+1))
>Here's solution for VFP
SELECT t1.un+1 AS unp, t1.un-1 AS unm, t1.un ;
>	FROM testun t1 ;
>	ORDER BY t1.un ;
>	INTO CURSOR crs1
>
>SELECT t1.unp AS uns, t1.un, RECNO() AS rn ;
>	FROM crs1 t1 ;
>	WHERE NOT EXISTS (SELECT * FROM crs1 t2 WHERE t2.un = t1.unp) ;
>	INTO CURSOR crs2
>
>SELECT t1.unm AS une, t1.un, RECNO()-1 AS rn ;
>	FROM crs1 t1 ;
>	WHERE NOT EXISTS (SELECT * FROM crs1 t2 WHERE t2.un = t1.unm) ;
>	INTO CURSOR crs3
>
>SELECT t2.uns, t3.une ;
>	FROM crs2 t2 ;
>		JOIN crs3 t3 ON t2.rn = t3.rn ;
>	INTO CURSOR crsResult
>
>
>>Hi everybody,
>>
>>Ok, I was inspired by Peter. Here is a very simple problem, but neverless, let's find out the most elegant solution.
>>
>>There is a table with some sequence unique numbers:
>>
>>1
>>3
>>4
>>8
>>15
>>...
>>
>>No pattern. Your goal would be to find out all missing numbers (of course, only whole numbers).
>>
>>For more advanced, I would make the task more difficult: find out all missing simple (? oops, what's the correct math term?) numbers. The latest problem seems complicated and I don't know solution myself yet...
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform