You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2015/rust/src/day_04.rs

28 lines
520 B

9 years ago
use crypto::md5::Md5;
use crypto::digest::Digest;
pub fn solve(input: &str) -> i32 {
let mut md5 = Md5::new();
let key = input.as_bytes();
let mut i = 0;
let mut out = [0; 16];
loop {
i += 1;
9 years ago
md5.input(key);
md5.input(i.to_string().as_bytes());
md5.result(&mut out);
if out[0] == 0 && out[1] == 0 && out[2] == 0 {
break;
9 years ago
}
md5.reset();
9 years ago
}
i
9 years ago
}
#[test]
#[ignore]
fn test_day04() {
assert_eq!(609043, solve("abcdef"));
9 years ago
}