add until day05-1

This commit is contained in:
timeshifter
2026-06-05 22:12:35 +02:00
parent 89c728010c
commit c7a5adc00a
26 changed files with 2326 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
#[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;
}
}
}