Question
Using Python 3.6.4: 10.33 In the simple coin game you are given an initial number of coins and then, in every iteration of the game,
Using Python 3.6.4:
10.33 In the simple coin game you are given an initial number of coins and then, in every iteration of the game, you are required to get rid of a certain number of coins using one of the following rules. If n is the number of coins you have then: If n is divisible by 10, then you may give back 9 coins.
If n is even, then you may give back exactly n/2 1 coins.
If n is divisible by 3, then you may give back 7 coins.
If n is divisible by 4, then you may give back 6 coins.
If none of the rules can be applied, you lose. The goal of the game is to end up with exactly 8 coins.
Note that more than one rule may be applied for some values of n. If n is 20, for example, rule 1 could be applied to end up with 11 coins. Since no rule can be applied to 11 coins, you would lose the game. Alternatively, rule 4 could be applied to end up with 14 coins, and then rule 2 could be applied to end up with 8 coins and win the game. Implement a function coins() that takes as input the initial number of coins and returns True if there is some way to play the game and end up with 8 coins. The function should return False only if there is no way to win.
>>> coins(7)
False
>>> coins(8)
True >>> coins(20)
True
>>> coins(66)
False >>> coins(99)
True
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started