Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Coding puzzle (4)
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00665368
Message ID:
00665503
Vues:
14
>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform