Minimal steps down to 1: Difference between revisions

Content added Content deleted
Line 239: Line 239:
end
end
if verbose
if verbose
print("There are ", length(solutions), " solutions for path of length ",
l = length(solutions)
numsteps, " from $start to $goal.\nExample: ")
print("There ", l > 1 ? "are $l solutions" : "is $l solution",
" for path of length ", numsteps, " from $start to $goal.\nExample: ")
for step in solutions[1]
for step in solutions[1]
print(step, step.out == 1 ? "\n\n" : ", ")
print(step, step.out == 1 ? "\n\n" : ", ")
Line 288: Line 289:
Example: divide 2 yields 1
Example: divide 2 yields 1


There are 1 solutions for path of length 1 from 3 to 1.
There is 1 solution for path of length 1 from 3 to 1.
Example: divide 3 yields 1
Example: divide 3 yields 1


Line 306: Line 307:
Example: divide 2 yields 4, divide 2 yields 2, divide 2 yields 1
Example: divide 2 yields 4, divide 2 yields 2, divide 2 yields 1


There are 1 solutions for path of length 2 from 9 to 1.
There is 1 solution for path of length 2 from 9 to 1.
Example: divide 3 yields 3, divide 3 yields 1
Example: divide 3 yields 3, divide 3 yields 1


There are 1 solutions for path of length 3 from 10 to 1.
There is 1 solution for path of length 3 from 10 to 1.
Example: subtract 1 yields 9, divide 3 yields 3, divide 3 yields 1
Example: subtract 1 yields 9, divide 3 yields 3, divide 3 yields 1


Line 319: Line 320:
For start of 1, no steps needed.
For start of 1, no steps needed.


There are 1 solutions for path of length 1 from 2 to 1.
There is 1 solution for path of length 1 from 2 to 1.
Example: divide 2 yields 1
Example: divide 2 yields 1