Consider a game with 2 players, computer and Eric, in which it starts with a ran
ID: 3875524 • Letter: C
Question
Consider a game with 2 players, computer and Eric, in which it starts with a random positive, nonzero number called n. Each player can subtract 4, 3, or 1 from the number. The objective of the game is to be the player that subtracts an amount to get to 0. Subtracting more than the number is not allowed. Given the number and who goes first, determine whom wins and how many ways they can win. If Eric goes first and the number is 4, 3, or 1, he will win. However, if the number is 2, he will lose.
A)Use recursion and write a program to solve the problem and assume that both players wish to win. Computer is always the second player
B)calculate the time complexity of your program (version1) in terms of n
C) change your code (version2) so that both players are computer
and n is determined by an input like c; i.e. 0 <n <c, where c is a positive
integer
D)Test your second version with big numbers as c (game.cpp). Does your program crash due to any run-time error or inefficient algorithm? If so please report n which causes the error. Also explain why this problem happens.
E)Change your code (version3) to make it efficiently working. Calculate the time complexity of version3 of your code.
Explanation / Answer
A)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.