r/adventofcode • • Dec 16 '16

SOLUTION MEGATHREAD --- 2016 Day 16 Solutions ---

--- Day 16: Dragon Checksum ---

Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/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".


DRINKING YOUR OVALTINE IS MANDATORY [?]

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!

4 Upvotes

116 comments sorted by

View all comments

Show parent comment

1

u/Zeroeh Dec 16 '16

You are using/creating wayyyy too many string objects, just in your generateData method, it creates two strings (via substring and the GenerateChecksumValue method) for every single iteration.

1

u/WildCardJoker Dec 17 '16 edited Dec 17 '16

I slept on it, and decided to go back and refactor it this morning. Funnily enough, it seems that it was the regex that was causing it to consume so much RAM. I wasn't happy with the GenerateData() method either, and I was able to reduce it to a single line:

input = $"{input}0{new string(input.Reverse().ToArray()).Replace('1', '-').Replace('0', '1').Replace('-', '0')}";

I've updated the repo, and both parts complete in less than 2 seconds.

Now I'm proud :)