Skip to content

Instantly share code, notes, and snippets.

@blahah
Created July 15, 2013 15:03
Show Gist options
  • Save blahah/6000677 to your computer and use it in GitHub Desktop.
Save blahah/6000677 to your computer and use it in GitHub Desktop.
Recursively generate all possible combinations from a hash of ranges (e.g. doing a parameter sweep)
require 'pp'
$ranges = {
:k => (21..90).step(4).to_a,
:d => (1..10).to_a
}
def nested_loop(index, opts)
if index == $ranges.length
# run command
pp opts
return
end
key = $ranges.keys[index]
for value in $ranges[key]
opts[key] = value
nested_loop(index + 1, opts)
end
end
nested_loop(0, {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment