-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Solve Day 15 #25
base: main
Are you sure you want to change the base?
Solve Day 15 #25
Conversation
Codecov Report
@@ Coverage Diff @@
## main #25 +/- ##
==========================================
- Coverage 94.77% 94.52% -0.26%
==========================================
Files 30 31 +1
Lines 574 584 +10
Branches 34 36 +2
==========================================
+ Hits 544 552 +8
- Misses 19 20 +1
- Partials 11 12 +1
Continue to review full report at Codecov.
|
* origin/main: rename repo from bionikspoon -> manuphatak (#27)
part1 = show . memoryGame 2020 . fromRightOrShowError . parseInts | ||
|
||
part2 :: String -> String | ||
part2 = show . memoryGame 30000000 . fromRightOrShowError . parseInts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: This runs too slowly to check.
* origin/main: Update dependencies (#41) Remove hspec skip rules from hlint (#39) Add hlint rule (#37) Solve Day 21 (#35) Refactor: Use LANGUAGE TypeApplications (#36) Solve Day 12 (#21) Solve Day 20 (#34) Solve Day 10 (#18) Harvest parseInts util (#33) Solve Day 18 (#31) Solve Day 17 (#30) Create Advent.Parser for shared parsers (#29) Solve Day 16 (#26) Add hspec-discover to PATH (#28)
Day 15: Rambunctious Recitation
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 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 :
0
.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
:1
st number spoken is a starting number,0
.2
nd number spoken is a starting number,3
.3
rd number spoken is a starting number,6
.6
. Since that was the first time the number had been spoken, the4
th number spoken is0
.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 (turn1
). Thus, the5
th number spoken is4 - 1
,3
.3
had also been spoken before, most recently on turns5
and2
. So, the6
th number spoken is5 - 2
,3
.3
was just spoken twice in a row, and the last two turns are1
turn apart, the7
th number spoken is1
.1
is new, the8
th number spoken is0
.0
was last spoken on turns8
and4
, so the9
th number spoken is the difference between them,4
.4
is new, so the10
th number spoken is0
.(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
2020
th number spoken? In the example above, the2020
th number spoken will be436
.Here are a few more examples:
1,3,2
, the2020
th number spoken is1
.2,1,3
, the2020
th number spoken is10
.1,2,3
, the2020
th number spoken is27
.2,3,1
, the2020
th number spoken is78
.3,2,1
, the2020
th number spoken is438
.3,1,2
, the2020
th number spoken is1836
.Given your starting numbers, what will be the
2020
th number spoken?Part Two
Impressed, the Elves issue you a challenge: determine the
30000000
th number spoken. For example, given the same starting numbers as above:0,3,6
, the30000000
th number spoken is175594
.1,3,2
, the30000000
th number spoken is2578
.2,1,3
, the30000000
th number spoken is3544142
.1,2,3
, the30000000
th number spoken is261214
.2,3,1
, the30000000
th number spoken is6895259
.3,2,1
, the30000000
th number spoken is18
.3,1,2
, the30000000
th number spoken is362
.Given your starting numbers, what will be the
30000000
th number spoken?Link
https://adventofcode.com/2020/day/15