(Simulation: The Tortoise and the Hare) In this problem, you’ll recreate one of the truly great moments in history, namely the classic race of the tortoise and the hare. You’ll use random number generation to develop a simulation of this memorable event.
Our contenders begin the race at “square 1” of 70 squares. Each square represents a possible position along the race course. The finish line is at square 70. The first contender to reach or pass square 70 is rewarded with a pail of fresh carrots and lettuce. The course weaves its way up the side of a slippery mountain, so occasionally the contenders lose ground.
There’s a clock that ticks once per second. With each tick of the clock, your program should adjust the position of the animals according to the rules of Fig. 7.31.
Use variables to keep track of the positions of the animals (i.e., position numbers are
Begin the race by printing
BANG !!!!!
AND THEY’RE OFF !!!!!
Then, for each tick of the clock (i.e., each iteration of a loop), print a 70-position line showing the letter T in the position of the tortoise and the letter H in the position of the hare. Occasionally, the contenders will land on the same square. In this case, the tortoise bites the hare and your program should print OUCH!!! beginning at that position. All print positions other than the T, the H, or the OUCH!!! (in case of a tie) should be blank.
After each line is printed, test whether either animal has reached or passed square 70. If so, then print the winner and terminate the simulation. If the tortoise wins, print TORTOISE WINS!!! H YAY!!! If the hare wins, print Hare wins. Yuch. If both animals win on the same tick of the clock, you may want to favor the turtle (the “underdog”), or you may want to print it’s a tie. If neither animal wins, perform the loop again to simulate the next tick of the clock. When you’re ready to run your program, assemble a group of fans to watch the race. You’ll be amazed at how involved your audience gets!
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
EBK C HOW TO PROGRAM
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (8th Edition)
Starting Out with Java: Early Objects (6th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Programming in C
Starting Out with Python (3rd Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- Python tic tac toe. Tic tac toe is a very popular game. Only two players can play at a time. Game Rules Traditionally the first player plays with "X". So you can decide who wants to go with "X" and who wants to go with "O". Only one player can play at a time. If any of the players have filled a square then the other player and the same player cannot override that square. There are only two conditions that may match will be a draw or may win. The player that succeeds in placing three respective marks (X or O) in a horizontal, vertical, or diagonal row wins the game. Winning condition Whoever places three respective marks (X or O) horizontally, vertically, or diagonally will be the winner. Submit your code and screenshots of your code in action. Hints : Have a function that draws the board Have a function that checks position if empty or not Have a function that checks player or won or not expected output:arrow_forwardPython tic tac toe. Tic tac toe is a very popular game. Only two players can play at a time. Game Rules Traditionally the first player plays with "X". So you can decide who wants to go with "X" and who wants to go with "O". Only one player can play at a time. If any of the players have filled a square then the other player and the same player cannot override that square. There are only two conditions that may match will be a draw or may win. The player that succeeds in placing three respective marks (X or O) in a horizontal, vertical, or diagonal row wins the game. Winning condition Whoever places three respective marks (X or O) horizontally, vertically, or diagonally will be the winner. Submit your code and screenshots of your code in action. Hints : Have a function that draws the board Have a function that checks position if empty or not Have a function that checks player or won or not expected output:arrow_forwardCorrect answer will be upvoted else downvoted. Computer science. After painting the white cells of the board, you want to place the maximum number of dominoes on it, according to the following rules: each domino covers two adjacent cells; each cell is covered by at most one domino; if a domino is placed horizontally (it covers two adjacent cells in one of the rows), it should cover only red cells; if a domino is placed vertically (it covers two adjacent cells in one of the columns), it should cover only blue cells. Let the value of the board be the maximum number of dominoes you can place. Calculate the sum of values of the board over all 2w possible ways to paint it. Since it can be huge, print it modulo 998244353. Input The first line contains two integers n and m (1≤n,m≤3⋅105; nm≤3⋅105) — the number of rows and columns, respectively. Then n lines follow, each line contains a string of m characters. The j-th character in the i-th string is * if the j-th cell in the i-th row…arrow_forward
- IN C PROGRAMMING LANGUAGE A resistor is a circuit device designed to have a specific resistance value between its ends. Resistance values are expressed in ohms (Ω) or kilo-ohms (kΩ). Resistors are frequently marked with colored bands that encode their resistance values, as shown in the Figure. The first two bands are digits, and the third is a power-of-ten multiplier. The Table below shows the meanings of each band color. For example, if the first band is green, the second is black, and the third is orange, the resistor has a value of 50 × 103 Ω or 50 k Ω. The information in the Table can be stored in a C program as an array of strings. char COLOR_CODES[10][7] = {"black", "brown", "red", "orange", "yellow", "green", "blue", "violet", "gray", "white"}; Notice that “red” is COLOR_CODES[2] and has a digit value of 2 and a multiplier value of 102. In general, COLOR_CODES[n] has digit value n and multiplier value 10n. Write a program that prompts for the colors…arrow_forwardPYTHON In order to parse data to start a simulation, users must enter data correctly. Suppose that the simulation requires 2 information from the user, which is called 'soil_key' and 'soil_data.' The user will enter 'soil_key' first, following with 'soil_data.' We need to check if the user enters the 'soil_data' data correctly. All elements in soil data ('soil_data') must be characters defined in the soil keys ('soil_key'). Both soil_key and soil_data are lists. Consider an example: INPUT: soil_key = ['C', 'Clay', ' B', 'Bedrock', ' V', 'Void'] soil_data1 = [ ['V', 'C', 'V'], ['C', 'V', ' '], ['B', 'M', 'B'] ] soil_data2 = [ ['B', 'C', 'V'], ['C', 'V', ' B'], ['B', 'C', 'B'] ] OUTPUT: soil_data1: check data again. Parsing failed! soil_data2: Parsing successfully. Write a python function that checks if the soil data is being entered correctly. Return True and print 'Parsing successfully' for correct data. Otherwise, return False and tells the user 'check data again. Parsing…arrow_forwardPlease do this in Python Programming Scenario As you probably know, Sudoku is a number-placing puzzle played on a 9x9 board. The player has to fill the board in a very specific way: each row of the board must contain all digits from 0 to 9 (the order doesn't matter) each column of the board must contain all digits from 0 to 9 (again, the order doesn't matter) each of the nine 3x3 "tiles" (we will name them "sub-squares") of the table must contain all digits from 0 to 9. If you need more details, you can find them here. Your task is to write a program which: reads 9 rows of the Sudoku, each containing 9 digits (check carefully if the data entered are valid) outputs Yes if the Sudoku is valid, and No otherwise. Test your code using the data we've provided. Test data Sample input: 295743861 431865927 876192543 387459216 612387495 549216738 763524189 928671354 154938672 Sample output: Yes Sample input: 195743862 431865927 876192543 387459216 612387495 549216738 763524189 928671354…arrow_forward
- See the sample outputs for more clarification. Project Specifications Input for this project: Values of the grid (row by row) Output for this project: Whether or not the grid is magic square Programmer's full name Project number Project due date Processing Requirements Use the following template to start your project: #include using namespace std; // Global constants // The number of rows in the array // The number of columns in the array // The value of the smallest number // The value of the largest number const int ROWS = 3; const int COLS = 3; const int MIN = 1; const int MAX = 9; // Function prototypes bool isMagicsquare(int arrayRow1[], int arrayRow2 [], int arrayRow3[], int size); bool checkRange (int arrayRow1[], int arrayRow2[], int arrayRow3[], int size, int min, int max); bool checkUnique(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size); bool checkRowSum (int arrayrow1[], int arrayrow2[], int arrayrow3[], int size); bool checkColiSum(int arrayrow1[], int…arrow_forwardWrite code using python or in python.arrow_forward[Python Language] Using loops of any kind, lists, or Sets is not allowed. Sloan’s Book Collection Sloan loves reading books. She recently started reading an AI generated series called “Harry Trotter”. Sloan is collecting books from the series at her nearest bookstore. Since the series is AI generated, the publishers have produced an infinite collection of the books where each book is identified by a unique integer. The bookstore has exactly one copy of each book. Sloan wants to buy the books in the range [l,r], where l ≤ r. As an example, the range [−3,3] means that Sloan wants to buy the books − 3, − 2, − 1, 0, 1, 2, and 3. Pam also loves the series (or maybe annoying Sloan– who knows, really), and he manages to sneak into the bookstore very early to buy all of the books in the range [d,u], where d ≤ u. When Sloan later visits, sadly she will not find those books there anymore. For example, if Sloan tries to buy books [−2,3] and Pam has bought books [0,2], Sloan would only receive…arrow_forward
- WATERSORT PROGRAM - JAVA •The aim of Part 2 is to set up the puzzle for the player to solve in Part 3. IMPORTANT NOTE: We are not going to start with 2 empty bottles, but rather with 8 empty slots spread over the 5 bottles as explained in the intro video. Start with 5 empty bottles. Use a random number generator to fill bottles one slot at a time with the colours while keeping 8 slots empty – there is a total of 5*4 = 20 slots – so if we will 12 slots, 8 are free. •Advantage: Easy to create a puzzle with a good mix •Disadvantage: With more colours and bottles and only 2 open bottles for more advanced versions of the game, the result might not be solvable. Start with three sorted bottles. In the strategy the idea is to load three bottles with uniform colour and then move ink around for a number of moves until the bottles are mixed up. •Advantage: Result is always solvable since the bottles are created in a reversed-game strategy. •Disadvantage: It is hard to develop an algorithm which…arrow_forwardSuppose that you are given an n × n checkerboard and a checker. You must move the checker from the bottom edge of the board to the top edge of the board according to the following rule. At each step you may move the checker to one of three squares: 1. the square immediately above 2. the square that is one up and one to the left (but only if the checker if not already in the leftmost column) 3. the square that is one up and one to the right (but only if the checker is not already in the rightmost column). 1 Each time you move from square x to square y, you receive p(x, y) dollars. You are given p(x, y) for all pairs (x, y) for which a move from x to y is legal. Do not assume that p(x, y) is positive. design a recursive backtracking algorithm that determines the maximum amount of money you can recieve, when moving a checker frmo somewhere on the bottom row to somewhere on the top row. your algorithm is free to pick any squrre along the bottom row as a starting point and any square along…arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr