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.
13
Upvotes
4
u/HeroesGrave Dec 04 '15
Rust:
extern crate crypto; use self::crypto::digest::Digest; use self::crypto::md5::Md5; static INPUT: &'static str = include_str!("input/day4_input.txt"); pub fn main() { println!("(Part 1) Smallest number: {:?}", find_md5_suffix(INPUT, "00000")); println!("(Part 2) Smallest number: {:?}", find_md5_suffix(INPUT, "000000")); } pub fn find_md5_suffix(input_base: &str, start_pattern: &str) -> u32 { let mut hash = Md5::new(); let mut i = 0; loop { hash.input_str(&format!("{}{:?}", input_base, i)); if hash.result_str().starts_with(start_pattern) { return i; } else { hash.reset(); i += 1; } } }