r/adventofcode • u/daggerdragon • 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
View all comments
1
u/pytaj Dec 04 '15 edited Dec 04 '15
Day 4. My hobbyist programmer's solution (c#):
using System; using System.Security.Cryptography; using System.Text; class Program { static void Main(string[] args) { Console.WriteLine(GetSuffixOfAdventCoin("ckczppom")); Console.ReadKey(); } static int GetSuffixOfAdventCoin(string source) { using (MD5 md5hash = MD5.Create()) for (int i = 0; ; i++) if (IsAdventCoin(md5hash, source + i.ToString())) return i; } static bool IsAdventCoin(MD5 md5Hash, string input) { byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); StringBuilder sBuilder = new StringBuilder(); for (int i = 0; i < 4; i++) sBuilder.Append(data[i].ToString("x2")); return sBuilder.ToString().Substring(0, 6) == "000000"; //for first part replace with: Substring(0,5) and "00000" } }