Skip to content

Commit f9010ca

Browse files
committed
feat(04/2015): solve first part for example, but is slow
1 parent 7a43fe7 commit f9010ca

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ edition = "2021"
99
aoc-client = "0.2.0"
1010
clap = { version = "4.5.21", features = ["derive"] }
1111
dotenv = "0.15.0"
12+
md5 = "0.8.0"
1213
regex = "1.11.1"
1314
itertools = "0.13.0"

src/solutions/year2015/day04.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
use crate::solutions::Solution;
2+
use md5::compute;
23

34
pub struct Day04;
45

56
impl Solution for Day04 {
6-
fn part_one(&self, _input: &str) -> String {
7-
String::from("0")
7+
fn part_one(&self, input: &str) -> String {
8+
for answer in 0u64.. {
9+
// println!("{}", answer);
10+
let hash = format!("{}{}", input, answer);
11+
let digest = compute(hash);
12+
13+
let x = format!("{:x}", digest);
14+
// println!("{}", x);
15+
if &x[0..5] == "00000" {
16+
return answer.to_string();
17+
}
18+
}
19+
20+
unreachable!();
821
}
922

1023
fn part_two(&self, _input: &str) -> String {
@@ -18,6 +31,7 @@ mod tests {
1831

1932
#[test]
2033
fn part_one_example_test() {
21-
assert_eq!("0", Day04.part_one(""));
34+
assert_eq!("609043", Day04.part_one("abcdef"));
35+
assert_eq!("1048970", Day04.part_one("pqrstuv"));
2236
}
2337
}

0 commit comments

Comments
 (0)