BotInc C++ Challenges

Discussion in 'Programming General' started by BotsInc, Aug 15, 2011.

BotInc C++ Challenges
  1. Unread #1 - Aug 15, 2011 at 5:06 AM
  2. BotsInc
    Joined:
    Aug 12, 2011
    Posts:
    78
    Referrals:
    0
    Sythe Gold:
    0

    BotsInc Member

    BotInc C++ Challenges

    First challenge:

    The ancient folklore behind the “Towers of Hanoi” puzzle is quite well known. A more recent legend tells us that once the Brahmin monks discovered how long it would take to finish transferring the 64 discs from the needle which they were on to one of the other needles, they decided to find a faster strategy and be done with it.

    The Four Needle (Peg) Tower of Hanoi
    One of the priests at the temple informed his colleagues that they could achieve the transfer in single afternoon at a one disc-per-second rhythm by using an additional needle. He proposed the following strategy:

    • First move the topmost discs (say the top k discs) to one of the spare needles.
    • Then use the standard three needles strategy to move the remaining n − k discs
    (for a general case with n discs) to their destination.
    • Finally, move the top k discs into their final destination using the four needles.

    He calculated the value of k which minimized the number of movements and found that 18,433 transfers would suffice. Thus they could spend just 5 hours, 7 minutes, and 13 seconds with this scheme versus over 500, 000 million years without the additional needle!

    Try to follow the clever priest’s strategy and calculate the number of transfers using four needles, where the priest can move only one disc at a time and must place each disc on a needle such that there is no smaller disc below it.

    Calculate the k that minimizes the number of transfers under this strategy.

    Input

    The input file contains several lines of input. Each line contains a single integer 0 ≤ N ≤ 10, 000 giving the number of disks to be transferred. Input is terminated by end of file.

    Output

    For each line of input produce one line of output which indicates the number of movements required to transfer the N disks to the final needle.

    Sample Input Sample Output
    1 1
    2 3
    28 769
    64 18433
     
  3. Unread #2 - Sep 17, 2011 at 3:49 PM
  4. spots13
    Joined:
    Feb 29, 2008
    Posts:
    213
    Referrals:
    0
    Sythe Gold:
    0

    spots13 Active Member
    $5 USD Donor New

    BotInc C++ Challenges

    nice challenge
    did it a while ago as a recursive challenge a teacher gave me
    well going to leave some people try to do it legit before posting the source code
    anyway good one hope you post the second one soon.

    good luck
     
  5. Unread #3 - Sep 18, 2011 at 12:24 PM
  6. wackywamba
    Joined:
    Jul 14, 2005
    Posts:
    1,358
    Referrals:
    0
    Sythe Gold:
    1

    wackywamba Guru

    BotInc C++ Challenges

    Ah :D what a classic question :)
     
< Mouse Recorder help | Starting C++ >

Users viewing this thread
1 guest


 
 
Adblock breaks this site