Guest User

Hot Potato

a guest
Jun 6th, 2013
247
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Hot Potato
  2.  
  3. There are N people seated at a round table. A hot potato is placed on the table.
  4. The potato is passed clockwise around the table to M-1 people. The Mth person
  5. to receive the potato leaves the table. The potato is then passed again.
  6. This procedure is repeated until the table is empty. The last person to leave
  7. is the winner.
  8.  
  9. Diagram of the Hot Potato solution when N = 9 and M = 5
  10.  
  11. 1 2 3 4 5 6 7 8 9 remove 5
  12.  
  13. 1 2 3 4 6 7 8 9 remove 1
  14.  
  15. 2 3 4 6 7 8 9 remove 7
  16.  
  17. 2 3 4 6 8 9 remove 4
  18.  
  19. 2 3 6 8 9 remove 3
  20.  
  21. 2 6 8 9 remove 6
  22.  
  23. 2 8 9 remove 9
  24.  
  25. 2 8 remove 2
  26.  
  27. 8 winner
  28.  
  29. Write a computer program to simulate the hot potato game. Given values
  30. for N and M as inputs, it should produce a display like the one above.
RAW Paste Data