add until day05-1
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user