File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -9,5 +9,6 @@ edition = "2021"
99aoc-client = " 0.2.0"
1010clap = { version = " 4.5.21" , features = [" derive" ] }
1111dotenv = " 0.15.0"
12+ md5 = " 0.8.0"
1213regex = " 1.11.1"
1314itertools = " 0.13.0"
Original file line number Diff line number Diff line change 11use crate :: solutions:: Solution ;
2+ use md5:: compute;
23
34pub struct Day04 ;
45
56impl 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}
You can’t perform that action at this time.
0 commit comments