Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!

# [very easy]transport the animals

Ellen Zhao
Ranch Hand
Posts: 581
This question was originally from a DB course, people were supposed to solve it by means of Petrinetz:
Say we have a mum elephant, baby elephant, mum tiger, baby tiger, mum lion and baby lion, they six are initially all at one bank of the river. There's a boat with capicity of 2 animals( no matter the animal is an adult or a baby ). A baby without its mum would be eaten by other adult. Say if you transport a baby tiger and baby lion to the other bank, but there's only a mum tiger waiting at the other bank, so the baby lion would be eaten by the mum tiger. Now try to transport all the animals safely to the other bank.

Greg Harris
Ranch Hand
Posts: 1012
ME = Mum Elephant
BE = Baby Elephant, etc...
• 1st trip - BT, BE -> leave BT, BE
• 2nd trip - ML, BT -> leave ML, BL

• after the 2nd trip, leave ML and BL - bring BE and BT back
• 3rd trip - ME, BE -> leave ME, BE
• 4th trip - MT, BT -> leave MT, BT

• all animals are on the other side

George Harris
Ranch Hand
Posts: 84
ME = Mommy Elephant
BE = Baby Elephant
ML = Mommy Lion
BL = Baby Lion
MT = Mommy Tiger
BT = Baby Tiger
Left Bank In Boat Right Bank
___________________________________________
ME BE MT BT ML BL
MT BT ML BL ME BE ->
MT BT ML BL <- ME BE
ME ML MT BT BL -> BE
ME ML MT <- BT BE BL
MT BT ME MT -> BE BT
MT BT <- ML BL ME BE
BT BL ML MT -> ME BE
BT BL <- BE ME ML MT
BE BT BL -> ME ML MT
BE <- BL ME ML MT BT
BE BL -> ME ML MT BT
ME BE ML BL MT BT

George Harris
Ranch Hand
Posts: 84
ME BE MT BT ML BL
MT BT ML BL ME BE ->
MT BT ML BL <- ME BE
ME ML MT BT BL -> BE
ME ML MT <- BT BE BL
MT BT ME MT -> BE BT
MT BT <- ML BL ME BE
BT BL ML MT -> ME BE
BT BL <- BE ME ML MT
BE BT BL -> ME ML MT
BE <- BL ME ML MT BT
BE BL -> ME ML MT BT
ME BE ML BL MT BT
Wow my formatting didn't work.
1) Send ME BE
2) Return ME (leave BE)
3) Send BL BT (leave BE BL)
4) Return BT
5) Send ME ML (leave ME BE)
6) Return ML BL
7) Send ML MT (leave ME ML MT)
8) Return BE
9) Send BT BE (leave ME ML MT BE)
10) Return BT
11) Send BT BL (all across)