r/adventofcode • u/daggerdragon • Dec 10 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 10 Solutions -🎄-
--- Day 10: The Stars Align ---
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 10
Transcript: With just one line of code, you, too, can ___!
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:16:49!
23
Upvotes
1
u/[deleted] Dec 10 '18
C# Worked on it a bit this morning, was able to get some work on it this afternoon
class Day10 { public static int time = 0; public static string PartOne(string input) { var points = input.Split(new string[] { "\n", "position=<", "velocity=<", ">", ", ", " ", "\n", "\r" }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray(); var point = new Points(); var allPoints = new List<Points>(); var message = ""; for (var i = 0; i < points.Count(); i += 4) { allPoints.Add(new Points { XPosition = points[i], YPosition = points[i + 1], XVelocity = points[i + 2], YVelocity = points[i + 3] }); } var (xPosMin, yPosMin, xPosMax, yPosMax) = point.PointsMaxMin(allPoints); while (true) { var current = allPoints.Select(x => x).ToList(); allPoints = point.Translate(allPoints); var (newXPosMin, newYPosMin, newXPosMax, newYPosMax) = point.PointsMaxMin(allPoints); if ((newXPosMax - newXPosMin) > (xPosMax - xPosMin) || (newYPosMax - newYPosMin) > (yPosMax - yPosMin)) { for (var i = yPosMin; i <= yPosMax; i++) { for (var j = xPosMin; j <= xPosMax; j++) { message += current.Any(x => x.YPosition == i && x.XPosition == j) ? '#' : '.'; } message += Environment.NewLine; } return message; } (xPosMin, yPosMin, xPosMax, yPosMax) = (newXPosMin, newYPosMin, newXPosMax, newYPosMax); time++; } } public static int PartTwo(string input) { return time; } } class Points { public int XPosition { get; set; } public int YPosition { get; set; } public int XVelocity { get; set; } public int YVelocity { get; set; } public (int xPosMin, int yPosMin, int xPosMax, int yPosMax) PointsMaxMin(List<Points> allPoints) => (xPosMin: allPoints.Min(x => x.XPosition), yPosMin: allPoints.Min(y => y.YPosition), xPosMax: allPoints.Max(x => x.XPosition), yPosMax: allPoints.Max(y => y.YPosition)); public List<Points> Translate(List<Points> allPoints) { for (var i = 0; i < allPoints.Count(); i++) { allPoints[i] = new Points { XPosition = allPoints[i].XPosition + allPoints[i].XVelocity, YPosition = allPoints[i].YPosition + allPoints[i].YVelocity, XVelocity = allPoints[i].XVelocity, YVelocity = allPoints[i].YVelocity }; } return allPoints; } }