Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

 

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:

Step by Step Solution

3.43 Rating (162 Votes )

There are 3 Steps involved in it

Step: 1

implement the game in Java MemoryGamejava import javautilArrayList import javautilScanner public cla... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intermediate Microeconomics and Its Application

Authors: Walter Nicholson, Christopher M. Snyder

12th edition

978-1133189022, 1133189024, 1133189032, 978-1305176386, 1305176383, 978-0357687000, 978-1133189039

More Books

Students also viewed these Programming questions