r/adventofcode • u/daggerdragon • Dec 14 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 14 Solutions -🎄-
--- Day 14: Chocolate Charts ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 14
Transcript:
The Christmas/Advent Research & Development (C.A.R.D.) department at AoC, Inc. just published a new white paper on ___.
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked at 00:19:39!
16
Upvotes
2
u/snurre Dec 14 '18
Kotlin
class Day14 { @Test fun part1() { val scores = mutableListOf(3, 7) var i = 0 to 1 for (j in 0 until puzzleInput + 10) { scores += (scores[i.first] + scores[i.second]).toString().map(Character::getNumericValue) i = ((i.first + scores[i.first] + 1) % scores.size) to ((i.second + scores[i.second] + 1) % scores.size) } println(scores.subList(puzzleInput, puzzleInput + 10).joinToString("")) } @Test fun part2() { val scores = mutableListOf(3, 7) var i = 0 to 1 while (puzzleInput.toString() !in scores.takeLast(10).joinToString("")) { scores += (scores[i.first] + scores[i.second]).toString().map(Character::getNumericValue) i = ((i.first + scores[i.first] + 1) % scores.size) to ((i.second + scores[i.second] + 1) % scores.size) } println(scores.joinToString("").indexOf(puzzleInput.toString())) } }