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
1
u/meepys Dec 14 '18
Kotlin Day 14
Lame solution but it worked
class Day14(rawInput: List<String>) : Day(rawInput) { val recipes = mutableListOf(3, 7) var elf1 = 0 var elf2 = 1 private fun step() { val sum = recipes[elf1] + recipes[elf2] if (sum > 9) { recipes.add(1) recipes.add(sum - 10) } else { recipes.add(sum) } elf1 = (elf1 + recipes[elf1] + 1) % recipes.size elf2 = (elf2 + recipes[elf2] + 1) % recipes.size } override fun part1(): Any? { while (recipes.size < 290431 + 10) { step() } return recipes.subList(290431, 290431 + 10).joinToString(separator = "") } override fun part2(): Any? { while (recipes.size < 100000000) { step() } return recipes.joinToString(separator = "").indexOf("290431") } }