Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Coding puzzle (4)
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00665368
Message ID:
00665503
Views:
13
>For those who know about asymptotic behavior:
>
>Given an array of increasing numbers and a number X, create a linear algorithm that finds whether the array contains two numbers that sum to X (and those two numbers if they exist).
>
>Daniel

Here is one solution (I think) with only one loop and I am also using the < pre > tags for the first time ;)
for i = 1 to alen(myarray)
  if ascan(myarray, X - myarray(i)) > 0
    return myarray(i), myarray(ascan(myarray, X - myarray(i)))
  endi
next i
  
Einar
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform