Skip to content

Commit

Permalink
Day 4, part 1 solved.
Browse files Browse the repository at this point in the history
  • Loading branch information
JPFrancoia committed Oct 19, 2021
1 parent 7608d84 commit a1a4fc6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
14 changes: 14 additions & 0 deletions day_4/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions day_4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "day_4"
version = "0.1.0"
authors = ["JPFrancoia <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
md5 = "0.7.0"
33 changes: 33 additions & 0 deletions day_4/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::{fs, u32};
use md5;


fn main() {
let key = fs::read_to_string("input.txt").unwrap();
let key = key.trim();

println!("Key: {}", key);

let mut counter = 0;

for n in 1..u32::MAX {
//println!("{}", n);
let input = format!("{}{}", key, n);
let digest = format!("{:x}", md5::compute(input.as_bytes()));

////For debug
//if n == 609043 {
//println!("{}", digest);
//println!("{}", digest.starts_with("00000"));
//break
//}

if digest.starts_with("00000") {
println!("{}", digest);
counter = n;
break
}
}

println!("Suffix: {}", counter);
}

0 comments on commit a1a4fc6

Please sign in to comment.