Re: Generating list of possible configurations





Mensanator wrote:
On Jul 2, 4:53 pm, "bjorklund.e...@xxxxxxxxx"
<bjorklund.e...@xxxxxxxxx> wrote:

After this I tried figuring out a function that would generate the
different possible configurations, but I couldn't quite wrap my head
around it...

Lookup "Cartesian Product".

Any pointers as to how one would go about
solving something like this would be greatly appreciated.

for a in [True,False]:
for b in [True,False]:
for c in [1,2,3,4]:
print 'combined settings:',a,'\t',b,'\t',c

This has been added to itertools at least for 2.6/3.0

>>> import itertools as it
>>> for prod in it.product((True,False), (True,False), (1,2,3,4)):
print(prod) # or run test

(True, True, 1)
(True, True, 2)
(True, True, 3)
(True, True, 4)
(True, False, 1)
(True, False, 2)
(True, False, 3)
(True, False, 4)
(False, True, 1)
(False, True, 2)
(False, True, 3)
(False, True, 4)
(False, False, 1)
(False, False, 2)
(False, False, 3)
(False, False, 4)

The sequences of sequences can, of course, be a variable:

>>> options = ((True,False), (True,False), (1,2,3,4))
>>> for prod in it.product(*options): print(prod)

does the same thing. So you can change 'options' without changing the test runner.

tjr

.



Relevant Pages

  • Re: better than a quartic?
    ... yeah, you're right, seems like I can't even type correctly:)) ... > You could solve the first equation for t1 and get a nice quadratic ... > The you choose some initial value for t5 and calculate the sequences ... I was thinking of solving the quartic, ...
    (sci.math.num-analysis)
  • Re: better than a quartic?
    ... yeah, you're right, seems like I can't even type correctly:)) ... > You could solve the first equation for t1 and get a nice quadratic ... > The you choose some initial value for t5 and calculate the sequences ... I was thinking of solving the quartic, ...
    (sci.math)
  • Re: Number sequence characterization
    ... There are infinitely many sequences which have any given finite ... solving such a quiz could be the first step for ... quiz: find not only the next number but give also the underlying law. ...
    (sci.math)
  • Re: Binomial Probabilities
    ... nC2 ^2 ^. ... Total number of different sequences with n tosses ... Number of sequences without one head = n ...
    (sci.math)