CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Puzzle

  1. #1
    Join Date
    Apr 2014


    The desert lies before you. Your mission is to plant a flag a four daysí march into the interior. You do not have any special equipment and must rely on your own powers. Carrying food and the flag itself is not a problem. The only limitation has to do with water: you can carry only a five-day supply of water. Thus, the amount of water you could bring with you would take you only two and a half days toward your destination and back to your
    starting point. Given these conditions, how can you fulfill your mission using at most a twelve-day supply of water? (You can assume that
    you have plenty of water at the starting point.)

  2. #2
    Join Date
    Aug 2013

    Re: Puzzle

    Quote Originally Posted by sls98 View Post
    how can you fulfill your mission using at most a twelve-day supply of water?
    So, 1 unit of water lasts for a 1 day's walk in the desert. You can carry at most 5 units of water at any given time. I assume you are allowed to deposit water in the desert and walk back and forth at will. Distance becomes measured in waterdays (in analogue with lightyears).

    Now, starting with 12 units of water, is there a strategy that will take you 4 waterdays out and back?

    One solution splits the journey into five legs. The first three take you 0.5 waterdays each into the desert. The fourth leg takes you the remaining 2.5 waterdays to plant the flag. At that point you have 2.5 units of water with you and 0.5 units at 3 deposits along the way. For the fifth leg these 4 units will sustain you during the 4 waterdays walk back home.

    With that information I'm sure you can figure out the details yourself but as a check: After the first leg you are 0.5 waterdays into the desert. Of the initial 12 units of water you have 9.5 with you. Of these you store up 0.5 units for later consumption and take 9 units with you for the next leg.

    This is an example of a variational problem where a resource (the water) is optimally conserved for the desired effect (take you the distance). Physics is full of the kind. It can be formulated mathematically but also solved like an ad-hoc puzzle if it's small like in this case. On the other hand a goal of higher education is to get beyond puzzles so I suggest you try to write a program that solves this more generally. Then you'll end up with an algorithm for a wider class of problems and not just a solution to one specific puzzle.
    Last edited by zizz; May 25th, 2014 at 11:19 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)