Using Search Algorithm in Python to solve the 3 Wolves and 3 Lambs puzzle
<p>I was thinking about this question for a long time and couldn't figure out how to solve it.</p>
<p>The problem is as following:</p>
<blockquote>
<p>We have 3 lambs and 3 wolves in a side and we have to let them pass the river to the other side. In the beginning it looked easy till i stopped with these difficult circumstances:</p>
<ul>
<li>The wolves can't be more than the lambs, which means the lambs can be more than or equal to the wolves.</li>
<li>The boat, which carries the animals to the other side, can't carry more than 2</li>
<li>The boat MUST be always carrying animals, which means you can't move an empty boat.</li>
</ul>
</blockquote>
<p>The question has to be solved by search algorithm, like A* or BFS etc.</p>
<p>We all know that these algorithms don't work until you provide a graph as an input, and here is the problem.</p>
<p>How we can create a graph from 3 lambs and 3 wolves?</p>
<p>I though about it many times, and the only way came to my mind is by all the possibilities. Sounds good for me, but still doesn't give me any progressing because the problem still the same, how to implement it or write it as a Python code to pass this graph to the algorithm so the algorithm can solve it?</p>