public void CompareSolves() { for (int s = 0; s < Solves.Count; s++) { var solve = Solves[s]; // Reset the sequences so we can match fresh Sequences.ForEach(s => s.Reset()); // Compare this solve to each sequence and consume an entry if matched // Reset the sequence if the cells don't match // Skip the sequence if it's already solved for (int sc = 0; sc < solve.Cells.Count; sc++) { var solveCell = solve.Cells[sc]; foreach (Sequence seq in Sequences) { if (seq.Solved) { continue; } bool recheck = true; while (recheck) { recheck = false; foreach (Cell seqCel in seq.Cells) { if (seqCel.Visited) { continue; } // First unmatched cell is now seqCel if (solveCell.Value == seqCel.Value) { seq.Used++; seqCel.Visited = true; // If we've visited all cells, mark it solved if (seqCel == seq.Cells.Last()) { seq.Solved = true; solve.Value += seq.Value; solve.SolvedValues.Add(seq.Value); if (seq.Started) { solve.Used += seq.Used; } } break; } else { // If the cell values don't match, reset the sequence seq.Reset(); seq.Started = false; if (seqCel != seq.Cells.First()) { recheck = true; } break; } } } } } } }