CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2019
    Posts
    3

    [RESOLVED] Trying to program advanced Sudoku techniques using C#

    Some of the techniques require building chains that jump from one candidate to another, sometimes to different cells, sometimes to different candidates within the same cell.

    The chain lengths can be anywhere between 4 and 30 nodes long, and the amount of possible chains that can be made is quite a large number.

    My code is technically working and can find the chains I am looking for, but it can take 20 seconds to find a single useful chain sometimes.

    Right now I am building the chains using nodes in a tree in a linked-list format, and using recursion to continue the chain. When a terminal node is found it is added to a list to be tested. Then it breaks the chain into smaller ones and tries them too.

    The problem is that I am probably building chains more than once (because a chain is the the same both forwards and backwards), and I am not sure how I can eliminate redundancy.

    Or maybe the problem is that I am using recursion and I should be using iteration, but I am not sure the best method to iterate with.

    This is the recursive call within the function:

    Code:
    if (currNode.children.Count > 0)
            {
                for (int n = 0; n < currChildCount; n++)
                {//Contine recursion on chilren
                    temp = currNode.children[n];
                    BuildAIC(temp, temp.note, terminalNodes, !findStrongLink);
    When the recursive loop finishes, I will have a list of all the terminal nodes which inherently link all the way back to their starting node.

    I iterate through each cell on the Sudoku grid and each note in each cell and then check the terminal nodes like this:

    Code:
    foreach (Point p in UnsolvedCells)
            {
                foreach (int note in cells[p.Y, p.X].notes.ToList())
                {
                    ancestor = new NodeAIC(p, note);
                    BuildAIC(ancestor, note, terminalNodes, true);
    
                    for (int n = 0; n < terminalNodes.Count; n++)
                    {
                          /* Test Chains Here */
    The recursive function is a void type, and the recursion exits when it cannot find any more links. This happens if A) there are no links to be found, or B) all possible links are already part of the current chain.

    Can anyone give me some ideas?

  2. #2
    Join Date
    Jul 2019
    Posts
    3

    Re: Trying to program advanced Sudoku techniques using C#

    For clarification, I am trying to make my code faster

  3. #3
    Join Date
    Jul 2019
    Posts
    3

    Re: Trying to program advanced Sudoku techniques using C#

    I resolved the problem!

    Instead of building one chain at a time, I made a color map of each step that two endpoints could take, and if at any time they hit the same note with the same color, then it must be able to form a link!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured