Я работаю над проектом, так как мы начинаем изучать рекурсию. Я очень новичок в этом, поэтому я не уверен, как решить эту загадку. Это проблема в книге, и я был бы признателен за любые STEPS (step1, step2, ...), которые могут помочь мне придумать идеи для решения этой проблемы. ТАКЖЕ, я очень признателен, если кто-то может поделиться со мной способом понять рекурсию, но для меня это не имеет большого смысла, поэтому я буду признателен за любые советы о том, как лучше понять эту тему. Хорошо, так что это инструкции. Спасибо.Recursion Additionpuzzle в java
AdditionPuzzle имеет такую форму, как 2BCD + BCDE = DA01. Мы хотим найти все решения, где A, B, C, D - разные цифры, отличные от любых цифр в головоломке. Здесь решение равно 2345 + 3456 = 5801. В общем, головоломка может иметь любую комбинацию из десяти цифр и цифр. Написать рекурсивный метод для вычисления решения головоломки, используя эти два класса:
Класс # 1
public class ThisPuzzle
{
/**
Returns a solution to a puzzle.
@param p a puzzle
@return a solution or null if none exists
*/
public static Puzzle solvePuzzle(Puzzle p)
{
// ...
return null;
}
public static void main(String[] args)
{
Puzzle p = new Puzzle("3A6", "36B", "71C");
System.out.println(solvePuzzle(p));
}
}
Класс # 2
public class Puzzle
{
private String add1;
private String add2;
private String result;
/**
Constructs a puzzle.
@param add1 a string containing digits 0 - 9 and letters
@param add2 a string containing digits 0 - 9 and letters
@param result a string containing digits 0 - 9 and letters
*/
public Puzzle(String add1, String add2, String result)
{
this.add1 = add1;
this.add2 = add2;
this.result = result;
}
/**
Makes a new puzzle by replacing a letter with a digit.
@param letter the letter to be replaced
@param digit the digit to replace it with
@return the new puzzle
*/
public Puzzle replace(String letter, int digit)
{
// ...
}
/**
Returns true if the puzzle is solved.
@return true if the puzzle has no letters and the
first two numbers add up to the third
*/
public boolean isSolved()
{
// ...
}
/**
Gets the first letter in this puzzle.
@return the first letter, or "" if there are no letters.
*/
public String firstLetter()
{
// ...
}
/**
Checks whether this puzzle contains a given digit.
@param digit a digit
@return true if this puzzle returns digit
*/
public boolean contains(int digit)
{
// ...
}
public String toString()
{
return add1 + "+" + add2 + "=" + result;
}
}