Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[very easy]transport the animals

 
Ellen Zhao
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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)
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic