G
Gary Boone
Suppose you want to do several runs of a program or function, varying
the parameters each time. You start with a hash of parameter lists:
params = { speed=>[1,2,3], beta=>[0.1, 0.002, 0.4], x=>['a', 'b'] }
Given this set, you'll call the test function 18 times:
test_function( {speed=>1, beta=>0.1, x=>'a'} )
test_function( {speed=>1, beta=>0.1, x=>'b'} )
test_function( {speed=>1, beta=>0.002, x=>'a'} )
... etc
So the puzzle is how to take the original params list and generate a
list of all the combinations of the parameters? The resulting parameter
sets will be passed one at a time to the function as shown above.
Notes:
- I used hashes and lists to explain the problem. Maybe there's a better
way.
- You don't know how many parameters will be given.
- The number of values for each parameter is unknown in advance.
- The parameters have different types, as shown above. Each parameter's
values are all the same type, though.
the parameters each time. You start with a hash of parameter lists:
params = { speed=>[1,2,3], beta=>[0.1, 0.002, 0.4], x=>['a', 'b'] }
Given this set, you'll call the test function 18 times:
test_function( {speed=>1, beta=>0.1, x=>'a'} )
test_function( {speed=>1, beta=>0.1, x=>'b'} )
test_function( {speed=>1, beta=>0.002, x=>'a'} )
... etc
So the puzzle is how to take the original params list and generate a
list of all the combinations of the parameters? The resulting parameter
sets will be passed one at a time to the function as shown above.
Notes:
- I used hashes and lists to explain the problem. Maybe there's a better
way.
- You don't know how many parameters will be given.
- The number of values for each parameter is unknown in advance.
- The parameters have different types, as shown above. Each parameter's
values are all the same type, though.