It's not a secret anymore!*
The moose likes Programming Diversions and the fly likes [very easy]transport the animals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "[very easy]transport the animals" Watch "[very easy]transport the animals" New topic
Author

[very easy]transport the animals

Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
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

Joined: Apr 12, 2001
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


    what?
    George Harris
    Ranch Hand

    Joined: May 05, 2003
    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

    Joined: May 05, 2003
    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)
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: [very easy]transport the animals
     
    Similar Threads
    why to create two classes?
    And Spain goes left..
    derived class reference cannot point to an object of base class
    I will fight for .....
    Stupid Elephant Jokes