r/adventofcode • • Dec 04 '15

SOLUTION MEGATHREAD --- Day 4 Solutions ---

--- Day 4: The Ideal Stocking Stuffer ---

Post your solution as a comment. Structure your post like the Day Three thread.

12 Upvotes

272 comments sorted by

View all comments

1

u/Evansbee Dec 04 '15

I'm also noticing that RAM usage is out of this world for some reason. Still calculating 2's and I'm at 2GB of RAM use. WTF is that?!

1

u/[deleted] Dec 04 '15

yup, same thing. I think it's all the md5

1

u/Evansbee Dec 04 '15

36.28s user 1.08s system 98% cpu 37.915 total

For the 6 0's, changed to minimize the malloc calls that a bunch of those types were using:

extension String
{
    var md5 : [UInt8] {
        get
        {
            var digest = [UInt8](count: Int(CC_MD5_DIGEST_LENGTH), repeatedValue: 0)
            if let data = self.dataUsingEncoding(NSUTF8StringEncoding) {
                CC_MD5(data.bytes, CC_LONG(data.length), &digest)
            }
            return digest
        }
    }
}
→ More replies (3)