×
Log in to StudySoup
Get Full Access to C++ For Everyone - 2 Edition - Chapter 4 - Problem P4.24
Join StudySoup for FREE
Get Full Access to C++ For Everyone - 2 Edition - Chapter 4 - Problem P4.24

Already have an account? Login here
×
Reset your password

The game of Nim. This is a well-known game with a number of variants. Thefol lowing

C++ for Everyone | 2nd Edition | ISBN: 9780470927137 | Authors: Cay S. Horstmann ISBN: 9780470927137 356

Solution for problem P4.24 Chapter 4

C++ for Everyone | 2nd Edition

  • Textbook Solutions
  • 2901 Step-by-step solutions solved by professors and subject experts
  • Get 24/7 help from StudySoup virtual teaching assistants
C++ for Everyone | 2nd Edition | ISBN: 9780470927137 | Authors: Cay S. Horstmann

C++ for Everyone | 2nd Edition

4 5 1 255 Reviews
21
2
Problem P4.24

The game of Nim. This is a well-known game with a number of variants. Thefol lowing variant has an interesting winning strategy. Two players alternately takemarbles from a pile. In each move, a player chooses how many marbles to take. Theplayer must take at least one but at most half of the marbles. Then the other playertakes a turn. The player who takes the last marble loses.You will write a program in which the computer plays against a human opponent.Generate a random integer between 10 and 100 to denote the initial size of the pile.Generate a random integer between 0 and 1 to decide whether the computer or thehuman takes the first turn. Generate a random integer between 0 and 1 to decidewhether the computer plays smart or stupid. In stupid mode the computer simplytakes a random legal value (between 1 and n2) from the pile whenever it has a turn.In smart mode the computer takes off enough marbles to make the size of the pile apower of two minus 1that is, 3, 7, 15, 31, or 63. That is always a legal move, exceptwhen the size of the pile is currently one less than a power of two. In that case, thecomputer makes a random legal move.You will note that the computer cannot be beaten in smart mode when it has the firstmove, unless the pile size happens to be 15, 31, or 63. Of course, a human player whohas the first turn and knows the win ning strategy can win against the computer.

Step-by-Step Solution:
Step 1 of 3

IT 100­ Week 14 Exam #3 (Tuesday, November 29, 2016) A. Wireless Security a. Wireless access poses additional security risks. b. Intruders intercept and monitor communications as they are sent/received. B. Ethics and Society a. Computer ethics i. Moral guidelines ii. Govern the use of computers, mobile devices, and information systems. b. Intellectual property­ unique and original works: ideas, inventions, writings, company and product names, and logos. c. Intellectual property rights­ rights to creators who are entitled to their work. d. A copyright­ protects tangible forms of expression. e. Digital rights management (DRM)­ strategy created to prevent illegal movie distribution, as well as music and other digital content illegally distributed. f. Code of Conduct­ written guideline that helps determine whether a specification is ethical/unethical or allowed/not allowed. C. Information Privacy­ info stored in a database when: i. Filling out printed or online forms ii. Creating a social networking profile iii. Registering product warranty b. Cookie­ small text file that a web server stores on your computer. i. Websites use cookies for: 1. Allow personalization 2. Store user names and passwords 3. Assist online shopping 4. Track number of users who visit a s

Step 2 of 3

Chapter 4, Problem P4.24 is Solved
Step 3 of 3

Textbook: C++ for Everyone
Edition: 2
Author: Cay S. Horstmann
ISBN: 9780470927137

Other solutions

Discover and learn what students are asking









Statistics: Informed Decisions Using Data : Comparing Three or More Means (One-Way Analysis of Variance)
?Corn Production The data in the table represent the number of corn plants in randomly sampled rows (a 17-foot by 5-inch strip) for various types of pl




People also purchased

Related chapters

Unlock Textbook Solution

Enter your email below to unlock your verified solution to:

The game of Nim. This is a well-known game with a number of variants. Thefol lowing