Aside the river there is 1 policeman, 1 robber, 1 blond hair woman and her 2 children and 1 red hair 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 hair woman is absent, the red hair woman will beat the blond hair woman’s children (and vice versa).
Step 1 :
Let us suppose some basic assumption : Let the right island = A and left island = B, Blond hair woman and her children be BW, B1 and B2, Red hair 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 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 hair women RW in 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 hair woman RW back to island A. Put thief and policeman back into 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 hair women RW in 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 children of red hair women R1 into 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 boat.
Step 15 :
Put thief back on island A and put last children R2 into 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 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 contribute.geeksforgeeks.org or mail your article to email@example.com. 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.