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...
-
Permanent disability can be a more expensive peril than death. Explain why this is so.
-
What is zoning?
-
Assume that Midway Cycles bought and sold a line of mountain bikes during May as follows: Midway Cycles uses the perpetual inventory system. Requirements 1. Compute the cost of ending inventory under...
-
Selected transactions for Arnett Advertising Company, Inc., are listed here. 1. Issued common stock to investors in exchange for cash received from investors. 2. Paid monthly rent. 3. Received cash...
-
A recipe for baked stuffed potatoes calls for 6 potatoes and yields 12 servings. If the yield percent for the potatoes is 81% and 1 potato weighs 5 ounces, how many pounds of potatoes will you need...
-
Walmart Stores, Inc. (Walmart) is the largest retailing firm in the world. Building on a base of discount stores, Walmart has expanded into warehouse clubs and Supercenters, which sell traditional...
-
I am going to "give you" $300,000 to invest, with the objective of growing it to $500,000 in 5 years so that you can take your $200,000 gain and use it as a down payment towards buying a house....
-
What is the purpose of the System Operations Model and how does it aid development of the ConOps?
-
Which System/Product Life Cycle Phases may not be covered by the ConOps and why?
-
What System/Product Life Cycle Phases are covered by the ConOps?
-
What Stakeholders have vested interests in a ConOps?
-
What are the key components of the Personnel Element? Give examples.
-
269. By definition, the perimeter of a rectangle is the sum of the lengths of its four sides. Which rectangle, of all those whose perimeter is 1, has the smallest area? Which one has the largest area?
-
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...
-
A part of a mechanism which operates a horizontally sliding block \(E\) is shown in Fig.3.23(a). In the given configuration, the lever \(O B\) swings about \(O\) in the clockwise direction with an...
-
In the mechanism shown in Fig.3.21(a), the link \(O_{1} A\) rotates at \(24 \mathrm{rad} / \mathrm{s}\). Find the velocity and acceleration of point \(B\). \(O_{1} A=75 \mathrm{~mm}, A B=200...
-
A double slider-crank mechanism is shown in Fig.3.22(a). Crank 2 rotates at constant angular speed \(\omega_{2}=10 \mathrm{rad} / \mathrm{s}\). Determine the velocity and acceleration of each slider....
Study smarter with the SolutionInn App