Tayyab-Ilahi12 / River-Crossing-Problem

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

River-Crossing-Problem

#My solution is only in the file riverProblem.py, Rest of the files are used for search and testing

#Problem: A farmer needs to move a hen, a fox, and a bushel of grain from the left side of the river to the right using a raft. The farmer can take one item at a time (hen, fox, or bushel of grain) using the raft. The hen cannot be left alone with the grain, or it will eat the grain. The fox cannot be left alone with the hen, or it will eat the hen. For example, the farmer cannot move from one side x of the river to the other side y if it would mean leaving the fox and hen together on side x. The farmer can load an item onto the raft, move the raft from one side of the river to the other, or unload an item from the raft. The farmer wants to move the items with the fewest number of trips across the river as possible.

#Solution: The man and the chicken cross the river, (the fox and corn are safe together), he leaves the chicken on the other side and goes back across. The man then takes the fox across the river, and since he can't leave the fox and chicken together, he brings the chicken back. Again, since the chicken and corn can't be left together, he leaves the chicken and he takes the corn across and leaves it with the fox. He then returns to pick up the chicken and heads across the river one last time.

About


Languages

Language:Python 100.0%