Question: public class SummationPuzzle { public static void main ( String [ ] args ) { solvePuzzle ( ) ; } static void solvePuzzle ( )
public class SummationPuzzle
public static void mainString args
solvePuzzle;
static void solvePuzzle
int digits ;
findSolutiondigits new int new boolean;
static void findSolutionint digits, int result, boolean used, int index
if index
All digits are assigned, check the equation
int a result;
int b result;
int c result;
Compute cbb ba
int cbb c b b; cbb
int ba b a; ba
int abc a b c; abc
if cbb ba abc
System.out.printlnSolution found: a a b b c c;
return;
Try each digit in the current position
for int i ; i digits.length; i
if usedi
usedi true; Mark this digit as used
resultindex digitsi; Assign this digit to the result
Recur to the next index
findSolutiondigits result, used, index ;
Backtrack
usedi false; Unmark this digit
explain this code, especially how the i and index value change
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
