title: Recursive nested loop c#
body: <p>I am trying to improve myself on probabilities with a task but couldn't figure it out:
  On a backgammon game, I have four (dynamic) rows of placements.</p>
  
  <p>So lets say row 5,7,11,13. I am throwing dynamic number of dice. I am trying to find the probabilities of each gameplay. As an example:</p>
  
  <p>I have thrown 4 dice and result is 1,3,4,6</p>
  
  <p>So </p>
  
  <p>I can play from the 5. row-1,3,4,6 dice</p>
  
  <p>I can play from the 5. row-1,3,4 dice and from the 7. row-6 dice</p>
  
  <p>I can play from the 5. row-3,1 dice and from the 11. row-6 dice and from the 13. row-4 dice
  etc etc.</p>
  
  <p>The dice have to be dynamic, the rows have to be dynamic, the dice can be played mixed like 1,3,4,6 or 6,1,4,3 or 3,1,6,4. And it has to calculate all the possibilities of different variations of dice spread on the rows.</p>
  
  <p>Simply I am trying to calculate the possibilities of play on a backgammon with unlimited dice. The method I am trying to use it to have a resizable possible moves class and inside of this class, there are the resizable rows class. Inside the rows class, there is resizable List moves variable. I am adding one move for each variation. This is the codes for non dynamic 4 dice.</p>
  
  <pre><code>public   List&lt;int&gt; dice;
  public   List&lt;int&gt; places;
  
  [System.Serializable]
  public class arrayData
  {
      public List&lt;arrayData2&gt; places = new List&lt;arrayData2&gt;();
      }
  
      public List&lt;arrayData&gt; pos = new List&lt;arrayData&gt;();
  
      [System.Serializable]
      public class arrayData2
      {
          public List&lt;int&gt; moves = new List&lt;int&gt; {};
      }
  
      void Start()
      {
          vs();
      }
  
      void vs()
      {
          for (int i = 0; i &lt; places.Count; i++)
          {
              for (int a = 0; a &lt; dice.Count; a++)
              {
                  for (int b = 0; b &lt; dice.Count; b++)
                  {
                      for (int c = 0; c &lt; dice.Count; c++)
                      {
                          for (int d = 0; d &lt; dice.Count; d++)
                          {
                              if (a == b || a == c || a == d || b == c || b == d || c == d)
                              {
                                  continue;
                              }
  
                              pos.Add(new arrayData());
  
                              for (int s = 0; s &lt; places.Count; s++)
                              {
                                  pos[pos.Count - 1].places.Add(new arrayData2());
                              }
  
                              pos[pos.Count - 1].places[i].moves.Add(dice[a]);
                              pos[pos.Count - 1].places[i].moves.Add(dice[b]);
                              pos[pos.Count - 1].places[i].moves.Add(dice[c]);
                              pos[pos.Count - 1].places[i].moves.Add(dice[d]);
                          }
                      }
                  }
              }
          }
      }
  </code></pre>
  
  <p>What I couldn't figure out:</p>
  
  <p>-Firstly, I tried to make it a recursive loop but I couldn't figure out the structure</p>
  
  <p>-Second, the output is giving me missing values for the variation of spread between rows: It gives such values: 5. row-1,3,4,6 dices but not such values: 5. row-3,1 dices and from the 11. row-6 dice and from the 13. row-4 dice</p>
  
  <p>I know it is a big question to ask but any kind of pointing out the mistake or correct direction leading would be so appreciated.</p>
  
  <p>Thanks</p>