Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do Factorials in VFP with Recursion
Message
De
22/02/2000 01:01:46
 
 
À
22/02/2000 00:06:50
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00335196
Message ID:
00335255
Vues:
20
>What 'types' of programs do you recommend using recursion? I've used them for multi-level types of organizations and relationships where they seem to do well. I'm curious as to other types of applications as well.

Here's the rule of thumb given by one of my professors:

You assume that:
1. You have a little devil-slave that knows how to calculate MyProblem(x)
and
2. You know how to go from y to x
and
3. You know when to stop

Then it's easy to apply a recursive solution:

func MyProblem
lparam y
if MyStopCondition(y)
return whatever && This is my precious knowledge
else
x = NextStepParam(y) && Again, my knowledge
a = MyProblem(x) && Again, my knowledge
return Operate(a, y) && Again, my knowledge
endif

And, as it can be seen, there's no little devil involved at all... :) The devil-slave is just the above pattern. In practice,
there are three important things: the above pattern, the stop condition (very important to be sure that it will
be meet for all cases) and the formula to go from one step to the other (params and result).

Obviously, NextStepParam and Operate can be simple formulas.

Vlad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform