Aside from the river, there is 1 policeman, 1 robber, 1 blond haired woman, and her 2 children and 1 red-haired woman and her 2 children. There is a boat having a carrying capacity of a maximum of 2 people. Only adults can sail but not the kids. Please help all people to move across the river, knowing that if the policeman is absent, the robber will kill all people there. If the blond haired woman is absent, the red-haired woman will beat the blond haired woman’s children (and vice versa).
Step 1 :
Let us suppose some basic assumption :
Let the right island = A and left island = B,
Blond haired woman and her children be BW, B1 and B2,
Red haired woman and her children be RW, R1 and R2.
Pick Policeman and thief from island A into boat and sail to island B.
Step 2 :
Drop Thief on island B and come back to island A with police.
Step 3 :
Now, Put one of the blond children B1 along with police in boat and sail to B.
Step 4 :
Drop B1 to island B and come back to island A along with policeman and thief.
Step 5 :
Drop Policeman and Thief to island A and put Blond women BW along with her second children B2 into boat and sail to island B.
Step 6 :
Put B2 at island B and sail back to island A with women BW.
Step 7 :
Put red-haired women RW in the boat along with BW and sail to island B.
Step 8 :
Drop blond women BW at island B and sail back to island A with red hair women RW.
Step 9 :Put off red-haired woman RW back to island A. Put thief and policeman back into the boat and sail to island B.
Step 10 :
Drop Policeman and thief at island B and sail to island A with Blond women BW.
Step 11 :
Put Red haired women RW in the boat with BW and sail to island B.
Step 12 :
Drop BW to Island B and sail back to island A with RW only.
Step 13 :
Put one of the children of red-haired women R1 into the boat along with red hair women RW and sail to island B.
Step 14 :
Put off both RW and R1 to island B and sail to island A with policeman and thief in the boat.
Step 15 :
Put thief back on island A and put last children R2 into the boat along with police and sail to island B.
Step 16 :
Put R2 on island B and sail to island A with policeman alone.
Step 17 :
Put thief back in the boat so that island A became empty and sail to island B.
Step 18 :
Here, you have reached island B with every person without breaking any of given the rule.
Game Source : River Crossing
This article is contributed by Shivam Pradhan (anuj_charm). If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.