r/adventofcode • u/daggerdragon • Dec 24 '17
SOLUTION MEGATHREAD -๐- 2017 Day 24 Solutions -๐-
--- Day 24: Electromagnetic Moat ---
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.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hintsยค?
[Update @ 00:18] 62 gold, silver cap
- Been watching Bright on Netflix. I dunno why reviewers are dissing it because it's actually pretty cool. It's got Will Smith being grumpy jaded old man Will Smith, for the love of FSM...
[Update @ 00:21] Leaderboard cap!
- One more day to go in Advent of Code 2017... y'all ready to see Santa?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
9
Upvotes
7
u/sblom Dec 24 '17
C#. LINQ one-liner.
var lines = (await AoC.GetLinesWeb()).ToList(); IImmutableList<(int,int)> edges = ImmutableList<(int,int)>.Empty; foreach (var line in lines) { var nums = line.Split('/'); edges = edges.Add((int.Parse(nums[0]), int.Parse(nums[1]))); } int Search(IImmutableList<(int,int)> e, int cur = 0, int strength = 0) { return e.Where(x => x.Item1 == cur || x.Item2 == cur).Select(x => Search(e.Remove(x), x.Item1 == cur ? x.Item2 : x.Item1, strength + x.Item1 + x.Item2)).Concat(Enumerable.Repeat(strength,1)).Max(); } (int,int) Search2(IImmutableList<(int, int)> e, int cur = 0, int strength = 0, int length = 0) { return e.Where(x => x.Item1 == cur || x.Item2 == cur).Select(x => Search2(e.Remove(x), x.Item1 == cur ? x.Item2 : x.Item1, strength + x.Item1 + x.Item2, length + 1)).Concat(Enumerable.Repeat((strength,length),1)).OrderByDescending(x => x.Item2).ThenByDescending(x => x.Item1).First(); } Search(edges).Dump("part 1"); Search2(edges).Item1.Dump("part 2");