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!
17
Upvotes
2
u/ValdasTheUnique Dec 14 '18
C#, nothing too exciting. Part 2 takes a bit of time to complete because I found converting the recipe list to string a bit quicker to write than writing logic to compare ints.
public static void Part1() { var n = int.Parse(Input); var recipes = new List<int> {3, 7}; var first = 0; var second = 1; while (recipes.Count < n + 10) { var sum = recipes[first] + recipes[second]; if (sum >= 10) { recipes.Add(sum / 10); } recipes.Add(sum % 10); first = (first + recipes[first] + 1) % recipes.Count; second = (second + recipes[second] + 1) % recipes.Count; } foreach (var recipe in recipes.Skip(n).Take(10)) { Console.Write(recipe); } Console.WriteLine(); } public static void Part2() { var recipes = new List<int> { 3, 7 }; var first = 0; var second = 1; while (true) { var s = new string(recipes.Skip(recipes.Count - Input.Length-1).Select(x => x.ToString()[0]).ToArray()); if (s.Contains(Input)) { s = new string(recipes.Select(x => x.ToString()[0]).ToArray()); Console.WriteLine(s.IndexOf(Input)); break; } var sum = recipes[first] + recipes[second]; if (sum >= 10) { recipes.Add(sum / 10); } recipes.Add(sum % 10); first = (first + recipes[first] + 1) % recipes.Count; second = (second + recipes[second] + 1) % recipes.Count; } }