Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Solve computational problems using a generic backtracking algorithm
ResourceFunction["BacktrackSearch"][s,ptest,test] performs a backtrack search of the solution space s, expanding a partial solution for as long as ptest gives True and returning the first valid solution satisfying test. | |
ResourceFunction["BacktrackSearch"][s,ptest,test,n] attempts to return n solutions. |
Use backtracking to find a way to partition an integer n into k smaller integers:
In[1]:= |
In[2]:= |
Out[2]= |
Find two possible partitions:
In[3]:= |
Out[3]= |
All partitions:
In[4]:= |
Out[4]= |
This work is licensed under a Creative Commons Attribution 4.0 International License