day15: Day 15: Rambunctious Recitation

Description Usage Arguments Details Value Examples

Description

Rambunctious Recitation

Usage

1
2
3
play_memory_game(x, max_turn = 2020)

example_memory_game(example = 1)

Arguments

x

The initial setup of the memory game.

max_turn

Number of steps to run the game. Defaults to 2020.

example

Which example data to use (by position or name). Defaults to 1.

Details

Part One

You catch the airport shuttle and try to book a new flight to your vacation island. Due to the storm, all direct flights have been cancelled, but a route is available to get around the storm. You take it.

While you wait for your flight, you decide to check in with the Elves back at the North Pole. They're playing a memory game and are [ever so excited]title="Of course they are." to explain the rules!

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:

So, after the starting numbers, each turn results in that player speaking aloud either 0 (if the last number is new) or an age (if the last number is a repeat).

For example, suppose the starting numbers are 0,3,6:

(The game ends when the Elves get sick of playing or dinner is ready, whichever comes first.)

Their question for you is: what will be the 2020th number spoken? In the example above, the 2020th number spoken will be 436.

Here are a few more examples:

Given your starting numbers, what will be the 2020th number spoken?

Part Two

Impressed, the Elves issue you a challenge: determine the 30000000th number spoken. For example, given the same starting numbers as above:

Given your starting numbers, what will be the 30000000th number spoken?

Value

play_memory_game(x) returns a list of vectors with game data.

Examples

1
2
game <- play_memory_game(example_memory_game(1))
game$last_num

tjmahr/adventofcode20 documentation built on Dec. 31, 2020, 8:39 a.m.