Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by Peter Zaffetti ( 14 years ago )
private void RecursiveSolve(SLinkedList U, SLinkedList S, int k) throws Exception

 { 

  if( k == 0)

  {

   int firstNum = this.getNumberFromPuzzlePiece(inputParts[0], S);

   int secondNum = this.getNumberFromPuzzlePiece(inputParts[1], S);

   int thirdNum = this.getNumberFromPuzzlePiece(inputParts[2], S);

   if(firstNum + secondNum == thirdNum)

   {

    System.out.println(S.toString());

    solutions++;

   }

   

  }

  else

  {

   for(int i = 0; i < U.size(); i++)

   {

    Node node1 = U.getHead();

    S.addFirst(node1);

    Node node = U.removeFirst();

    uReturn.addFirst(node);

    this.RecursiveSolve(U, S, k - 1);

    U.addLast(uReturn.removeFirst());

    S.removeFirst();

       

   }

   

  }

 }



 private int getNumberFromPuzzlePiece( String puzzlePiece, SLinkedList mappingList ) throws Exception

 {

  int numberForPuzzlePiece = 0;

  if(this.uniqueLettersList.size() != mappingList.size())

  {

   throw new Exception

   (

     "Number of unique letter (" + 

       this.uniqueLettersList.size() + ")"

       + "is not equal to the mapping size (" +

       mappingList.size() + ")" 

     );

  }



  /**

   *This is a loop that iterates through the characters in the string provided

   */

  for(int i = 0; i < puzzlePiece.length() ;  i++)

  {

   /** This takes the first character out of the string provided and makes a new string of that character*/

   String l = puzzlePiece.substring(i, i + 1); 



   /** This creates a node that points to the head of the singly linked list of unique letters list*/

   Node uniqueLetterNode = uniqueLettersList.getHead(); 

   

   /** This creates a node that points to the head of the singly linked list mappingList which is provided*/

   Node mappingListNode = mappingList.getHead();

   

   



   /** This loop iterates until the string in the node matches the string l created above*/

   while(true) 

   {

    /** The next step checks to see if the information stored in the node is equal to the string l*/

    if( uniqueLetterNode.element == (Object)l.charAt(0)) 

    {

     /** This step multiplies the number corresponding to the letter in the mappingList by its respective magnitude*/

     numberForPuzzlePiece += ( (Integer)mappingListNode.getElement() * Math.pow( 10, (puzzlePiece.length() - i ) ) ) ;

     break;      

    }

    else 

    {

     /** If the if statement is not true, then we get the next uniqueLetterNode and mappingListNode*/

     uniqueLetterNode = uniqueLetterNode.getNext();

     mappingListNode = mappingListNode.getNext();

    }

   }

  }

  

  return numberForPuzzlePiece;

 }

 

Revise this Paste

Your Name: Code Language: