A
Allan Bruce
I have a program which I need to be able to produce all the possible states
from a given set of variables. This requires me to have a variable number
of nested loops, depending on how many derivativest the user specifies.
What is the best way to do this? I was considering limiting the number of
derivatives and using if statements but this is quite messy. Am I
describing my problem clear enough? If not then look below for an example
problem.
A state in my system holds the current values of my world variables. Each
variable has a number of derivatives specified by the user, and each
derivative has a number of possible values specified by the user. For
example, one simple problem is this:
3 variables: V, qi, qo
V has 3 derivatives, and qi/qo both have only 2
the first derivative of each variable can have 9 possible values, and the
rest of the derivatives can have 5
For this system there are 9x5x5 possible values for V (=225)
there are 9x5 possible values for qo (=45)
there are 9x5 possible values for qi (=45)
therefore there are 225x45x45 possible states in the system (=455625)
Can anybody shed some light as to how I would approach this problem?
Thanks
Allan
from a given set of variables. This requires me to have a variable number
of nested loops, depending on how many derivativest the user specifies.
What is the best way to do this? I was considering limiting the number of
derivatives and using if statements but this is quite messy. Am I
describing my problem clear enough? If not then look below for an example
problem.
A state in my system holds the current values of my world variables. Each
variable has a number of derivatives specified by the user, and each
derivative has a number of possible values specified by the user. For
example, one simple problem is this:
3 variables: V, qi, qo
V has 3 derivatives, and qi/qo both have only 2
the first derivative of each variable can have 9 possible values, and the
rest of the derivatives can have 5
For this system there are 9x5x5 possible values for V (=225)
there are 9x5 possible values for qo (=45)
there are 9x5 possible values for qi (=45)
therefore there are 225x45x45 possible states in the system (=455625)
Can anybody shed some light as to how I would approach this problem?
Thanks
Allan