my solutions to advent of code
aoc advent-of-code
1use md5::{Digest, Md5}; 2 3// just putting it here that the idea of analysing it as bytes instead of a string and of putting the main hasher outside the loop was gemini 4fn find(input: &str, requires: usize) -> u32 { 5 let mut i = 1; 6 let div_ceiled = requires.div_ceil(2) - 1; 7 let starts_with = &[0_u8].repeat(requires / 2); 8 9 let mut hasher_main = Md5::new(); 10 hasher_main.update(input.as_bytes()); 11 12 loop { 13 let mut hasher = hasher_main.clone(); 14 hasher.update(i.to_string().as_bytes()); 15 let result = hasher.finalize(); 16 if result[div_ceiled] < 16 && result.starts_with(starts_with) { 17 return i; 18 } 19 i += 1; 20 } 21} 22 23fn main() { 24 let input = 25 std::fs::read_to_string("../input.txt").expect("invalid input!!"); 26 let input = input.trim(); 27 28 let res = find(input, 5); 29 println!("{}", &res); 30 31 let res = find(input, 6); 32 println!("{}", &res); 33}