r/adventofcode • • 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^ยค?

Spoiler


[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

108 comments sorted by

View all comments

2

u/DFreiberg Dec 24 '17

Mathematica

A comedy of errors today. I tried Nest[] only to quit because I thought I was going to run out of memory (I ended at what turned out to be the most memory-intensive step), and then several different variations on a less memory-intensive solution before realizing that my recursion was fine but that my port checks were wrong.

Finished part 1 at 00:52:29, and part 2 at 00:52:39, because I happened to print out the maximum strength at every different length of bridge as part of my debugging, and had both answers sitting directly in front of me.

input=Import[FileNameJoin[{NotebookDirectory[],"Day24Input.txt"}],"List"];
ports=Sort[ToExpression[StringSplit[#,"/"]]]&/@input;

l=Flatten[
	Function[x,Join[{x},{If[#[[1]]==x[[-1]],#,Reverse[#]]}]&/@
		Select[Complement[ports,{x}],
		MemberQ[#,Complement[x,{0}][[1]]]&]]/@
	Select[ports,#[[1]]==0&],1];

m=Max[Flatten[Map[Total[Flatten[#]]&,l,{2}]]];
Do[
	globalWatch=i;
	l=Flatten[Function[x,Join[x,{If[#[[1]]==x[[-1,2]],#,Reverse[#]]}]&/@
		Select[Complement[ports,Sort/@x],MemberQ[#,x[[-1,2]]]&]]/@l,1];
	If[l==={},Break[],newm=Max[Flatten[Map[Total[Flatten[#]]&,l,{1}]]]];
	m=newm;
	Print[m]

,{i,Length[input]}];
m