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.

14 Upvotes

272 comments sorted by

View all comments

Show parent comment

2

u/JustCallMeLee Dec 04 '15

Might substr be ever so slightly faster? Here you're still searching for five zeros anywhere in the string when we're only interested in the start.

2

u/adriweb Dec 04 '15 edited Dec 04 '15

Probably indeed, I'll try :)

Edit: surprisingly, no! With part 2, 6.6s with strpos and 6.9s with substr. I haven't looked at the internal, but I suppose strpo doesn't allocate a new string, making it faster.