title: CS50 Tideman: lock_pairs skips final pair if it creates cycle
body: <p>After many failed attempts, I managed to used a recursive function to check the locked pairs.
  When I check the results, both with the program and manually, I get the correct locked pairs. But I keep getting the &quot;lock_pairs skips final pair if it creates cycle&quot; error, while all other checks run ok.</p>
  <p>I don't know how to see what's wrong here. Can you give me a hand?
  I'm not asking for someone to tell me how to do it properly, but to point out where is my error, so I can think of the best way to work this out.</p>
  <p>Here is my code:</p>
  <pre><code>bool find_connections(int i, int j);
  int lock_done = 100;
  
  
  void lock_pairs(void)
  {
      // Iterates through all the pairs
      for (int i = 0; i &lt; pair_count; i++)
      {
          // lock_done is used in the recursive function as indicator that the locked value is false, and every further process of the loop is unnecessary.
          lock_done = 100;
          // Calls find_connection function, and sends the index of the pair twice, one for checking the cycle (it remains constant) and one to be replaced by the losing candidate of the found pair.
          int is_locked = find_connections(i, i);
          locked[pairs[i].winner][pairs[i].loser] = is_locked;
      }
  return;
  }
  
  
  bool find_connections(int i, int j)
  {
  
      // Iterates through all pairs to check for a coincidence between loser of j and winner of r
      for (int r = 0; r &lt; pair_count; r++)
      {
          // If it was confirmed as false, it returns &quot;false&quot;
          if (lock_done != 100)
              return lock_done;
  
          // Checks coincidence between loser of j and winner of r
          if (pairs[j].loser == pairs[r].winner)
          {
              // When there's a match, if pair is locked and the loser connects to the original winner, then the lock condition is false.
              if (pairs[i].winner == pairs[r].loser &amp;&amp; locked[pairs[r].winner][pairs[r].loser] == 1)
                  {
                      lock_done = 0;
                      return 0;
                  }
              // Otherwise, it calls the function again to check the connections starting with the new pair.
              else if(locked[pairs[r].winner][pairs[r].loser] == 1)
                  find_connections(i, r);
          }
      }
  
      // When all pairs are checked, if one was already found as false, then it returns false.
      if (lock_done == 0)
          return 0;
      // Otherwise, there is no cycle, and the locked condition is true.
      else
      {
          lock_done = 1;
          return 1;
      }
  }
  </code></pre>