28 lines
636 B
Rust
28 lines
636 B
Rust
#[cfg(debug_assertions)]
|
|
const FILENAME: &str = "example.txt";
|
|
#[cfg(not(debug_assertions))]
|
|
const FILENAME: &str = "input.txt";
|
|
|
|
fn main() {
|
|
let data = std::fs::read_to_string(FILENAME).unwrap();
|
|
|
|
part_1_and_2(data.trim(), 5);
|
|
part_1_and_2(data.trim(), 6);
|
|
}
|
|
|
|
fn part_1_and_2(key: &str, length: usize) {
|
|
for i in 1.. {
|
|
let mut input = String::from(key);
|
|
input.push_str(&i.to_string());
|
|
|
|
let hash = md5::compute(input);
|
|
|
|
let hash_str = format!("{:x?}", hash);
|
|
|
|
if hash_str.chars().take(length).all(|c| c == '0') {
|
|
println!("{i}");
|
|
break;
|
|
}
|
|
}
|
|
}
|