title: Nested combinations – options spread over multiple questions
body: <p>I'm looking at analyzing a test. It consists of four questions with ten options each. From each question, three options must be selected. That of course always yields a total of 12 answers.</p>
  
  <p>Analyzing the number of possible combinations using Ruby's [].combination my Dell Workstations freezes up and fails to produce sane values. Is that calculation really so extremely intense/large?</p>
  
  <p>Using 40 options over 12 answers, I figured I should run:</p>
  
  <pre><code>[0...39].combination(12){|x| p x }
  </code></pre>
  
  <p>I also found <a href="http://en.wikipedia.org/wiki/Combination" rel="nofollow noreferrer">the Wikipedia article on Combination</a>. But being handicapped in terms of math, it really did not make my any smarter.</p>
  
  <p>I would madly appreciate any help I can get on this matter. Thanks everybody.</p>
  
  <p><strong>Secondary/follow-up question:</strong></p>
  
  <p>Plus points to anyone who can figure out a smart way to generate all possible combinations. It's needed for a "offline" Ruby application simulating all possible answers. My brain is dizzy from analyzing the docs – but I cannot seem to find an efficient way to achieve this task.</p>
  
  <p>Ideally, I would need one giant array containing ints representing the options selected:</p>
  
  <pre><code>[[0, 1, 2], [0, 1, 2], [0, 1, 2], [0, 1, 2]]
  </code></pre>
  
  <p>...would for example represent a scenario where question one, two, three and four was answered using options 0, 1 and 2.</p>