Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This card game requires a certain number of cards, n, where the n is a triangular number. A triangular number is a number that represent
This card game requires a certain number of cards, n, where the n is a triangular number. A triangular number is a number that represent the sum of the sequence: 1, 2, 3, 4, etc. For example, 21 123+4+56. The first few triangular numbers are 1, 3, 6, 15, 21, 28, 36, 45, etc. The Game: You will start the game with 45 cards. Divide the cards into a random number of piles. Each round, take one card from each pile and create a new one. Repeat the process until you have 9 piles of sizes 1, 2, 3, 4,5, 6, 7, 8, and 9 For example, if you start with 4 piles of 20, 15, 6, and 4, they would be transformed into 19,14, 5, 3, and 4, etc. Simulator Write a C++ program that simulates the game. Start by producing a random number of piles Make sure the total is 45. Apply the steps outlined above repeatedly until the final configuration is reached. At each step, print the number of cards in each of the piles. The final configuration is reached when the number of cards in the piles are 1, 2, 3, 4, 5, 6, 7, 8, and 9 Display the number of steps it took to reach the final configuration Hints: . Store the number of cards in each pile into an array of integers . To generate a random number use the function rand () in o First seed the random number generator with the current time. Do this only once in the program (beginning of main) ' srand (time (NULL)) To generate a random integer between 0 and 2147483647 ' randomIntegerrand ) Write a function that checks if the game is done by confirming the last sequence. You may want to sort the values to make it easier to check. . Extra Credit: Fix your program to accept any triangular number from the keyboard. Please complete the original requirements before attempting the extra credit. This card game requires a certain number of cards, n, where the n is a triangular number. A triangular number is a number that represent the sum of the sequence: 1, 2, 3, 4, etc. For example, 21 123+4+56. The first few triangular numbers are 1, 3, 6, 15, 21, 28, 36, 45, etc. The Game: You will start the game with 45 cards. Divide the cards into a random number of piles. Each round, take one card from each pile and create a new one. Repeat the process until you have 9 piles of sizes 1, 2, 3, 4,5, 6, 7, 8, and 9 For example, if you start with 4 piles of 20, 15, 6, and 4, they would be transformed into 19,14, 5, 3, and 4, etc. Simulator Write a C++ program that simulates the game. Start by producing a random number of piles Make sure the total is 45. Apply the steps outlined above repeatedly until the final configuration is reached. At each step, print the number of cards in each of the piles. The final configuration is reached when the number of cards in the piles are 1, 2, 3, 4, 5, 6, 7, 8, and 9 Display the number of steps it took to reach the final configuration Hints: . Store the number of cards in each pile into an array of integers . To generate a random number use the function rand () in o First seed the random number generator with the current time. Do this only once in the program (beginning of main) ' srand (time (NULL)) To generate a random integer between 0 and 2147483647 ' randomIntegerrand ) Write a function that checks if the game is done by confirming the last sequence. You may want to sort the values to make it easier to check. . Extra Credit: Fix your program to accept any triangular number from the keyboard. Please complete the original requirements before attempting the extra credit
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