Question

For this problem you need to use Mutual Recursion. This means one function will call another...

For this problem you need to use Mutual Recursion. This means one function will call another function which will call the first function once again.

This game is two-player game. There are m matches in a box. The players will take turns to remove matches. The player who takes the last match wins. Your friends decided to stick to a certain strategy:

1) Steve loves magic numbers. If the number of matches is divisible by 4, Steve will remove 3 matches, otherwise he will remove only 1 match. If there are 2 or less matches, Steve will take them both and win.

2) Kate loves even numbers. If the number of matches is even, Kate will remove 2 matches, otherwise she will only take 1 (so that the number of matches is even again!). If there are 2 or less matches, Kate will take them both and win.

Assume that there are m matches and the player function called goes first, who wins the game?

Output: You are expected to return one of the following strings, verbatim:

  • "Steve wins the game"
  • "Kate wins the game"
def steve(n):
    """
    >>> steve(1)
    "Steve wins the game"
    >>> steve(5)
    "Steve wins the game"
    """
    # YOUR CODE GOES HERE #
def kate(n):
    """
    >>> kate(1)
    "Kate wins the game"
    >>> kate(2)
    "Kate wins the game"
    """
    # YOUR CODE GOES HERE #
0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here is the simple code in python.

====================================================================================

def steve(n):
    if n<=2:
        print('Steve wins the game')
        return
    if
n%4==0:
        kate(n-3)
    else:
        kate(n-1)

def kate(n):
    if n<=2:
        print('Kate wins the game')
        return
    if
n%2==0:
        steve(n-2)
    else:
        steve(n-1)

steve(1)
steve(5)
kate(1)
kate(2)

====================================================================================

def steve (n): if n<=2: print (steve wins the game) return kate (n-3) else: kate (n-1) def kate (n) if n<-2: print (Kate w

thanks !

Add a comment
Know the answer?
Add Answer to:
For this problem you need to use Mutual Recursion. This means one function will call another...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to complete the code by implementing the min function and the alpha betta pruning...

    I need to complete the code by implementing the min function and the alpha betta pruning in order to complete the tic tac toe game using pything. code: # -*- coding: utf-8 -*- """ Created on: @author: """ import random from collections import namedtuple GameState = namedtuple('GameState', 'to_move, utility, board, moves') infinity = float('inf') game_result = { 1:"Player 1 Wins", -1:"Player 2 Wins", 0:"It is a Tie" } class Game: """To create a game, subclass this class and implement actions,...

  • How to call a function in another function?C++ Project assistance. In the Project I am attempting...

    How to call a function in another function?C++ Project assistance. In the Project I am attempting to pass getOutcome into runGame to attempt to figure out who would win. Upon trying I get an error that getOutcome isn't in scop of runGame. The & symbols were my last attempt at trying to pass it, I do see it is wrong, and any help that can help me with just that is very appreciated. #include <iostream> #include <fstream> #include <string> #include...

  • MATCHING (HINT: one of the terms is used twice!) 1. A serve that strikes the net...

    MATCHING (HINT: one of the terms is used twice!) 1. A serve that strikes the net but it's otherwise good. 2. Situation in which if the receiver wins the next point, they will win the game. 3. Unsuccessful attempt at a second serve. A. Unforced error B. Winner 4. A point lost by one's mistake rather than caused by the difficulty of the opponent's shot. C. Break point 5. Situation in which if a player wins the next point, they...

  • def st_petersburg_lottery(): print("###### St. Petersburg Lottery ######") print("Instructions:") print("You will select any number greater than 0.")...

    def st_petersburg_lottery(): print("###### St. Petersburg Lottery ######") print("Instructions:") print("You will select any number greater than 0.") print("Up to the number of times you chose, we will randomly choose 0 or 1.") print("If a 1 is chosen before the last drawing, then you lose.") print("If a 1 does not appear at all, then you lose.") print("You win if 1 is chosen for the first time exactly on the last drawing.") print() def first_to_a_word(): print("###### First to a Word ######") print("Instructions:") print("You...

  • Instructions sevens.py 1 # Put your code here In the game of Lucky Sevens, the player...

    Instructions sevens.py 1 # Put your code here In the game of Lucky Sevens, the player rolls a pair of dice. If the dots add up to 7, the player wins $4; otherwise, the player loses $1. Suppose that, to entice the gullible, a casino tells players that there are lots of ways to win: (1,6), (2,5), and so on. A little mathematical analysis reveals that there are not enough ways to win to make the game worthwhile; however, because...

  • A subtraction game Subtraction games are two-player games in which there is a pile of objects,...

    A subtraction game Subtraction games are two-player games in which there is a pile of objects, say coins. There are two players, Alice and Bob, who alternate turns subtracting 4.9. A SUBTRACTION GAME 19 from the pile some number of coins belonging to a set S (the subtraction set). Alice goes first. The first player who is unable to make a legal move loses. For example, suppose the initial pile contains 5 coins, and each player can, on his turn,...

  • can someone solve this program using c++ (visual studio)? You have a grid of 4x4 cells...

    can someone solve this program using c++ (visual studio)? You have a grid of 4x4 cells which is filled by numbers from 1 to 8. Each number appears twice in the grid. The purpose of the Memory Game is to find the matching numbers. To start the game, Player 1 chooses two cells to uncover the numbers behind them. If the numbers match, player 1 gets to go on and uncover two more numbers. If the numbers don't match, player...

  • Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic will allow the player to: 1) Pick any 6 integer numbers from 1 - 70. Your logic should prev...

    Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic will allow the player to: 1) Pick any 6 integer numbers from 1 - 70. Your logic should prevent the player from selecting a value LESS than 1 or greater than 70. The logic should prevent the player from selecting the SAME number (i.e. they cannot have two or more of their selections be the SAME number). 2) Display the players' 6 number selections...

  • First, you will need to create the Creature class. Creatures have 2 member variables: a name,...

    First, you will need to create the Creature class. Creatures have 2 member variables: a name, and the number of gold coins that they are carrying. Write a constructor, getter functions for each member, and 2 other functions: - void addGoldCoins(int) adds gold coins to the Creature. - void identify() prints the Creature information. The following should run in main: Creature d{"dragon", 50}; d.addGoldCoins(10); d.identify(); // This prints: The dragon is carrying 60 gold coins. Second, you are going to...

  • This program should be in c++. Rock Paper Scissors: This game is played by children and...

    This program should be in c++. Rock Paper Scissors: This game is played by children and adults and is popular all over the world. Apart from being a game played to pass time, the game is usually played in situations where something has to be chosen. It is similar in that way to other games like flipping the coin, throwing dice or drawing straws. There is no room for cheating or for knowing what the other person is going to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT