void search(State state, List<Choice> path, List<List<Choice>> answer) {
if (complete(state)) {
answer.add(new ArrayList<>(path));
return;
}
for (Choice choice : choices(state)) {
if (!valid(state, choice)) continue;
apply(state, choice);
path.add(choice);
search(state, path, answer);
path.remove(path.size() - 1);
undo(state, choice);
}
}
def search(state, path, answer) -> None:
if complete(state):
answer.append(path.copy())
return
for choice in choices(state):
if not valid(state, choice):
continue
apply(state, choice)
path.append(choice)
search(state, path, answer)
path.pop()
undo(state, choice)
def search(state: State, path: List[Choice], answer: scala.collection.mutable.Buffer[List[Choice]]): Unit =
if complete(state) then answer += path
else
for choice <- choices(state) do
if valid(state, choice) then
applyChoice(state, choice)
search(state, path :+ choice, answer)
undoChoice(state, choice)
void search(State& state, std::vector<Choice>& path, std::vector<std::vector<Choice>>& answer) {
if (complete(state)) {
answer.push_back(path);
return;
}
for (const Choice& choice : choices(state)) {
if (!valid(state, choice)) continue;
apply(state, choice);
path.push_back(choice);
search(state, path, answer);
path.pop_back();
undo(state, choice);
}
}