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
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 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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
