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/xkufix Dec 04 '15

Nice, I did basically the same algorithm, just in Scala.

Stream.from(1).dropWhile(n => !java.security.MessageDigest.getInstance("MD5").digest(("ckczppom" + n).getBytes).map("%02X".format(_)).mkString.startsWith("00000")).head

2

u/jgagnon1 Dec 04 '15

Is there a reason why you didn't use find instead of dropWhile ?

1

u/xkufix Dec 04 '15

Uhm, actually no, good input. That would make it shorter, as the call to "head" could be dropped.

I started with takeWhile, but this returned the number before the needed one, so I just switched over to dropWhile.