This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

[very easy]transport the animals  RSS feed

 
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.
 
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
     
    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)
     
    All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
    RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
    https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!