title: Algorithm to get "adjacent" values of a list with subsets
body: <p>I have a text file like this:</p>
  
  <pre><code>A
  B
  C
  </code></pre>
  
  <p>And each element has a subset like this:</p>
  
  <pre><code>A = { a1, a2, a3 }
  B = { b1, b2 }
  C = { c1, c2, c3 }
  </code></pre>
  
  <p>I want to generate this:</p>
  
  <pre>
      a1, b1, c1
      <b>a2</b>, b1, c1
      <b>a3</b>, b1, c1
      a1, <b>b2</b>, c1
      a1, b1, <b>c2</b>
      a1, b1, <b>c3</b>
  </pre>
  
  <p>I don't know the number of elements in the text file (e.g. could be: A, B, C, D, E) and the subsets could vary in size.</p>
  
  <p>All I can think it's a recursive function with 2 indexes, maybe "position in the array" and "index of the array", but I really don't know how to implement all of this.</p>
  
  <p>I even tried to adapt a function that does cartesian product with the same inputs, but I totally failed. <strong>I don't need to generate Cartesian product</strong>.</p>