From: Daniel Moore Date: 2009-05-02T00:47:19+09:00 Subject: [QUIZ] One Die Game (#203) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The three rules of Ruby Quiz: 1. Please do not post any solutions or spoiler discussion for this quiz until 48 hours have elapsed from the time this message was sent. 2. Support Ruby Quiz by submitting ideas and responses as often as you can! Visit: 3. Enjoy! Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone on Ruby Talk follow the discussion. Please reply to the original quiz message, if you can. RSS Feed: http://rubyquiz.strd6.com/quizzes.rss -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ## One Die Game (#203) Hej Rubyists, This week's quiz was submitted by Siep Korteling through the suggestions page . Imagine a two player game with the following rules: - Playing material: 1 ordinary die; opposing sides sum up to 7. - The first move consists of the first player rolling the die and initializing the total to the amount on the face shown. - All further moves consist of turning the die one quarter and adding the face value of the new side to the current total. Example: If the die is facing 2 after the initial throw, then possible moves are 1,3,4 and 6, with totals 3,5,6 and 8. - A player wins when that player's move results in a total of 31. - A player loses when that player overshoots 31. Let's say it's your turn. The current total is 24 and the die is facing 3. You can win by turning the die to face 6, totaling 30. Your opponent cannot play 1 because it's at the bottom of the die, so he is forced to overshoot the goal of 31. Build a program which plays this game against a human opponent and blunders occasionally (to keep it fun). P.S. I did not invent this game; I'm pretty sure I found this game in a chapter about nim-like games[1] in one of Martin Gardner's books. [1]: http://en.wikipedia.org/wiki/Nim Have Fun! -- -Daniel http://rubyquiz.strd6.com