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.

16 Upvotes

272 comments sorted by

View all comments

Show parent comment

1

u/fortee Dec 07 '15

My solution is getting exex time error, and I cant figure out why your's is running so much faster. I understand what you did, just not why it's so much faster.

My solution: $input = 'yzbqklnj'; $i = 1; $gotit = false;

    while ($gotit == false) {

        $hash = md5($input . $i);
        if (substr($hash, 0, 5) === '000000') {
            $gotit = true;
            return $i;
        }
        $i++;
    }

1

u/fortee Dec 07 '15

I'm so stupid.... substr($hash, 0, 5) === '000000'

I was using 5 as the length of substr...