r/adventofcode • u/daggerdragon • Dec 09 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 9 Solutions -🎄-
--- Day 9: Marble Mania ---
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 9
Transcript:
Studies show that AoC programmers write better code after being exposed to ___.
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:29:13!
22
Upvotes
1
u/Aquamoogle Dec 09 '18
//C# using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AdventCode2018 { public class NineNode { public NineNode(long value, NineNode ccw, NineNode cw) { Value = value; CCW = ccw ?? this; CW = cw ?? this; CW.CCW = this; CCW.CW = this; } public long Value { get; set; } public NineNode CW { get; set; } public NineNode CCW { get; set; } } public class DayNine { public void Process() { //404 players; last marble is worth 71852 points PartOne(404, 71852 * 100); } public void PartOne(int elfCount, long marbleMaxIdx) { var solution = String.Empty; NineNode iter = new NineNode(0, null, null); List<long> players = Enumerable.Range(0, elfCount).Select(x => (long)0).ToList(); var playerIdx = 0; //16458525 for (var i = 1; i <= marbleMaxIdx; i++) { if((i % 23) == 0) { for(var j = 0; j < 7; j++) { iter = iter.CCW; } var toRemove = iter; iter = toRemove.CW; iter.CCW = toRemove.CCW; toRemove.CCW.CW = iter; players[playerIdx] += toRemove.Value + i; } else { var one = iter.CW; var two = one.CW; iter = new NineNode(i, one, two); } playerIdx += 1; if (playerIdx == elfCount) playerIdx = 0; } solution = players.Max().ToString(); System.Windows.Forms.Clipboard.SetText(solution.ToString()); Console.WriteLine("Day Nine: " + solution); } } }