add until day05-1
This commit is contained in:
Generated
+16
@@ -0,0 +1,16 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "day04"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"md5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "md5"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae960838283323069879657ca3de837e9f7bbb4c7bf6ea7f1b290d5e9476d2e0"
|
||||
@@ -0,0 +1,7 @@
|
||||
[package]
|
||||
name = "day04"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
md5 = "0.8.0"
|
||||
@@ -0,0 +1 @@
|
||||
abcdef
|
||||
@@ -0,0 +1 @@
|
||||
yzbqklnj
|
||||
@@ -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