master
dece 3 years ago
parent 7f9920447a
commit a903132905

9
2015/Cargo.lock generated

@ -3,3 +3,12 @@
[[package]]
name = "aoc2015"
version = "0.1.0"
dependencies = [
"md5",
]
[[package]]
name = "md5"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "490cc448043f947bae3cbee9c203358d62dbee0db12107a74be5c30ccfd09771"

@ -8,3 +8,4 @@ edition = "2018"
name = "aoc"
[dependencies]
md5 = "0.7.0"

@ -0,0 +1,30 @@
use aoc::input;
fn main() {
let lines = input::read_lines();
let mut key = lines[0].to_string();
let key_len = key.len();
// Part 1
let mut n = 0;
loop {
key.replace_range(key_len.., &n.to_string());
let hash = md5::compute(key.as_bytes());
if &hash[..2] == [0, 0] && hash[2] < 0x10 {
break
}
n += 1
}
println!("Found coin with n {}.", n);
// Part 2
loop {
key.replace_range(key_len.., &n.to_string());
let hash = md5::compute(key.as_bytes());
if &hash[..3] == [0, 0, 0] {
break
}
n += 1
}
println!("Found coin with n {}.", n);
}
Loading…
Cancel
Save