r/adventofcode • • Dec 05 '16

SOLUTION MEGATHREAD --- 2016 Day 5 Solutions ---

--- Day 5: How About a Nice Game of Chess? ---

Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).


STAYING ON TARGET 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!

14 Upvotes

188 comments sorted by

View all comments

Show parent comment

1

u/xkufix Dec 05 '16

That's what the take(6) does, so it only makes a string out of the first 7 chars (needed to get the result for the second part):

    MessageDigest.getInstance("MD5").digest(toHash.getBytes).take(6).map("%02X" format _).mkString

2

u/orukusaki Dec 05 '16 edited Dec 05 '16

It's still a lot quicker to not format it or convert it to a string until you know it's a match. Edit: The 3 conditions in my IF statement is a trick too. The 2nd and 3rd bytes won't get evaluated unless the first is a 0, so in 9 out of 10 iterations, I'm only evaluating a single byte.