In General, problems of this kind are reduced to the contrary, proof of the existence of the algorithm.
There are a few universal basic methods of proof: by contradiction, induction, invariant, etc.
To solve this problem, you need to highlight a few key points concerning your problem:
1. The source data
2. Some of the actions with them
3. How to change data in the process
4. What should come out of it
Based on this it is possible to apply the above methods, for example, to assume that such an algorithm exists, or, for example, to make the induction step and determine whether all of the cases are conditions. In this context, your initial conditions are axioms, they are indestructible and do not require evidence. On the basis of axioms, you can build some lemmas - are currently "partial proof" - some of the more complex provisions that are derived from axioms, and later help in the final proof. It should also be remembered that the condition of the evidence can be artificially enhanced in order to make it easier to prove your entire theorem.
More about this you can listen to
lectures from MIT.