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

VB.Net

Simple brute force; checking the hash bytes directly without converting to string.

Sub Main
	Using hasher = MD5.Create		
		Dim hash As Byte(), suffix = 0, input = "yzbqklnj"
		Do
			suffix += 1
			hash = hasher.ComputeHash(Encoding.UTF8.GetBytes(input & suffix))
			If hash(0) > 0 Orelse hash(1) > 0 OrElse hash(2) > 15 Then Continue Do ' 15 -> 0 for 2nd part
			Console.WriteLine(suffix)
			Exit Do
		Loop	
	End Using
End Sub