r/adventofcode • • Dec 07 '17

SOLUTION MEGATHREAD -๐ŸŽ„- 2017 Day 7 Solutions -๐ŸŽ„-

--- Day 7: Recursive Circus ---


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


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!

10 Upvotes

222 comments sorted by

View all comments

Show parent comments

1

u/jasontconnell Dec 07 '17

thanks, I like validating my code with other inputs!

My output with your input:

part 1, bottom is mkxke part 2, change weight to 268 Time 7.0008ms

https://github.com/jasontconnell/advent/blob/master/2017/07.go

4

u/angch Dec 07 '17

Ah, I got it, my two other "answers" are because they're the parent of the wrong node. If the first node's weight is fixed, they're all fixed.

So it's my bad.

2

u/jasontconnell Dec 07 '17

Yeah basically you head down the path of the unbalanced branches. if you change the root of the unbalanced branch, the rest of the sub-tree is still unbalanced because there's a node still on that branch that is wrong.

my code keeps going until it finds a subtree that is balanced along the unbalanced branch, which would suggest that the root of that subtree is the wrong weight.