You're playing a memory game! In this game, the players take turns saying numbers. They begin...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
You're playing a memory game! In this game, the players take turns saying numbers. They begin by taking turns reading from a list of starting numbers (your puzzle input). Then, each turn consists of considering the most recently spoken number: > If that was the first time the number has been spoken, the current player says 0. > Otherwise, the number had been spoken before; the current player announces how many turns apart the number is from when it was previously spoken. For example, suppose the starting numbers are [0,3,6]: • Turn 1: The Ist number spoken is a starting number, 0. • Turn 2: The 2nd number spoken is a starting number, 3. Turn 3: The 3rd number spoken is a starting number, 6. Turn 4: Now, consider the last number spoken, 6. Since that was the first time the number had been spoken, the 4th number spoken is 0. Turn 5: Next, again consider the last number spoken, 0. Since it had been spoken before, the next number to speak is the difference between the turn number when it was last spoken (the previous turn, 4) and the turn number of the time it was most recently spoken before then (turn 1). Thus, the 5th number spoken is 4 - 1, 3. Turn 6: The last number spoken, 3 had also been spoken before, most recently on turns 5 and 2. So, the 6th number spoken is 5- 2. 3. • Turn 7: Since 3 was just spoken twice in a row, and the last two turns are l turn apart, the 7th number spoken is I. Turn 8: Since 1 is new, the 8th number spoken is 0. Turn 9: 0 was last spoken on turns 8 and 4, so the 9th number spoken is the difference between them, 4. Turn 10: 4 is new, so the 10th number spoken is 0. In the example above, the 2020th number spoken will be 436. Write down a program which will find the 2020th number spoken according to following starting numbers: You're playing a memory game! In this game, the players take turns saying numbers. They begin by taking turns reading from a list of starting numbers (your puzzle input). Then, each turn consists of considering the most recently spoken number: > If that was the first time the number has been spoken, the current player says 0. > Otherwise, the number had been spoken before; the current player announces how many turns apart the number is from when it was previously spoken. For example, suppose the starting numbers are [0,3,6]: • Turn 1: The Ist number spoken is a starting number, 0. • Turn 2: The 2nd number spoken is a starting number, 3. Turn 3: The 3rd number spoken is a starting number, 6. Turn 4: Now, consider the last number spoken, 6. Since that was the first time the number had been spoken, the 4th number spoken is 0. Turn 5: Next, again consider the last number spoken, 0. Since it had been spoken before, the next number to speak is the difference between the turn number when it was last spoken (the previous turn, 4) and the turn number of the time it was most recently spoken before then (turn 1). Thus, the 5th number spoken is 4 - 1, 3. Turn 6: The last number spoken, 3 had also been spoken before, most recently on turns 5 and 2. So, the 6th number spoken is 5- 2. 3. • Turn 7: Since 3 was just spoken twice in a row, and the last two turns are l turn apart, the 7th number spoken is I. Turn 8: Since 1 is new, the 8th number spoken is 0. Turn 9: 0 was last spoken on turns 8 and 4, so the 9th number spoken is the difference between them, 4. Turn 10: 4 is new, so the 10th number spoken is 0. In the example above, the 2020th number spoken will be 436. Write down a program which will find the 2020th number spoken according to following starting numbers:
Expert Answer:
Answer rating: 100% (QA)
implement the game in Java MemoryGamejava import javautilArrayList import javautilScanner public cla... View the full answer
Related Book For
Intermediate Microeconomics and Its Application
ISBN: 978-1133189039
12th edition
Authors: Walter Nicholson, Christopher M. Snyder
Posted Date:
Students also viewed these programming questions
-
Consider a two-player, sequential-move game where each player can choose to play right or left. Player 1 moves first. Player 2 observes player 1s actual move and then decides to move right or left....
-
It has now been two years since you advised Eddie to switch to the perpetual inventory method. He is very happy with the additional information he has about inventory levels and theft. He has hired...
-
Now suppose this project has an investment timing option, since it can be delayed for a year. The cost will still be $70 million at the end of the year, and the cash flows for the scenarios will...
-
1. Conduct a SWOT analysis for HHI's proposed electronic commerce Web site. You can use the information in the case narrative, your personal knowledge of the retail hardware industry, and information...
-
When the magnetic flux through a single loop of wire increases by 30 T m2, an average current of 40 A is induced in the wire. Assuming that the wire has a resistance of 2.5 , (a) Over what period of...
-
Define each term related to optical isomerism: enantiomers, chiral, dextrorotatory, levorotatory, racemic mixture.
-
Assume that ABC Corp. just paid a dividend of $1 a share and that all future dividends are expected to grow at the rate of 9 percent per year. If the required rate of return for this stock is 15...
-
Dreiling Company borrowed $300,000 on January 1, 2017, by issuing a $300,000, 8% mortgage note payable. The terms call for annual installment payments of $40,000 on December 31. Instructions (a)...
-
IN AGHI, GH || JK. Given that IG=35, GH=49, and JK=21, find IJ. G K J H IJ = 0
-
In a single process production system, Honest Company produces Product Z.For October, 2021, the company accounting records reflect the following: Beginning Work In Process (50% complete as to...
-
Q1: Company has $1,400 indirect expenses. Following are the three departments through which a product manufactures. Company's costing record provided the following information for the month of June,...
-
a bathroom scale could also be used to determine the gravitational field strength. An 80kg astronaut is working on the surface of a small asteroid and steps on a bathroom scale. If the scale reads...
-
What is the formula for calculating profit margin? Explain the meaning of each variable used in the calculation
-
Give fifteen (15) risks/problems encountered by credit cooperatives on collection of loans/payments.
-
1) A battery of 5 V is hooked up to a resistor of 10. What is the current? 2) A battery is hooked up to a resistor of 30 2 and the ammeter reads a current of 0.2 A. What is the voltage of the...
-
The following data has been provided by Lee Company regarding its inventory purchases and sales throughout the year. Transaction Units Cost per Unit January 1 Balance 185 $86 March 14 Sale 54 May 23...
-
Forecasted Statements and Ratios Upton Computers makes bulk purchases of small computers, stocks them in conveniently located warehouses, ships them to its chain of retail stores, and has a staff to...
-
Linda Lopez opened a beauty studio, Lindas Salon, on January 2, 2011. The salon also sells beauty supplies. In January 2012, Lopez realized she had never filed any tax reports for her business and...
-
Suppose that historical data showed that returns of Japanese stocks and returns on U.S. stocks tended to move in opposite directions. Would it be better to own only one country's stocks or to hold a...
-
P. T. Blowhard is the CEO of Ditch Industries. He was heard to make the following statement about his choice of inputs for digging ditches: "We borrowed $100,000 to buy this Ditch Witch, and we're...
-
Why is it a good idea to bid your (known) valuation in a second-price, sealed-bid auction? Why is it a bad idea to bid your (known) valuation in a first-price, sealed-bid auction? Explain, with...
-
Rocket Fireworks is evaluating a new firework, the Asian Candle, that can be sold for $45 each. The following information pertains to the Asian Candle: a. What are the estimated life-cycle revenues?...
-
Taylor Processing Company uses a weighted-average process costing system and manufactures a single product-a premium rug shampoo and cleaner. The manufacturing activity for the month of October has...
-
Nicholas Company manufactures basketballs and soccer balls. For both products, materials are added at the beginning of the production process and conversion costs are incurred uniformly. Nicholas...
Study smarter with the SolutionInn App