@@ -3,8 +3,16 @@ use crate::solutions::Solution;
33pub struct Day01 ;
44
55impl Solution for Day01 {
6- fn part_one ( & self , _input : & str ) -> String {
7- String :: from ( "0" )
6+ fn part_one ( & self , input : & str ) -> String {
7+ input
8+ . bytes ( )
9+ . map ( |b| match b {
10+ b'(' => 1 ,
11+ b')' => -1 ,
12+ _ => 0 ,
13+ } )
14+ . sum :: < isize > ( )
15+ . to_string ( )
816 }
917
1018 fn part_two ( & self , _input : & str ) -> String {
@@ -14,13 +22,18 @@ impl Solution for Day01 {
1422
1523#[ cfg( test) ]
1624mod tests {
17- use crate :: solutions:: year2024:: day01:: Day01 ;
18- use crate :: solutions:: Solution ;
19-
20- const EXAMPLE : & str = r#""# ;
25+ use super :: * ;
2126
2227 #[ test]
2328 fn part_one_example_test ( ) {
24- assert_eq ! ( "0" , Day01 . part_one( EXAMPLE ) ) ;
29+ assert_eq ! ( "0" , Day01 . part_one( "(())" ) ) ;
30+ assert_eq ! ( "0" , Day01 . part_one( "()()" ) ) ;
31+ assert_eq ! ( "3" , Day01 . part_one( "(((" ) ) ;
32+ assert_eq ! ( "3" , Day01 . part_one( "(()(()(" ) ) ;
33+ assert_eq ! ( "3" , Day01 . part_one( "))(((((" ) ) ;
34+ assert_eq ! ( "-1" , Day01 . part_one( "())" ) ) ;
35+ assert_eq ! ( "-1" , Day01 . part_one( "))(" ) ) ;
36+ assert_eq ! ( "-3" , Day01 . part_one( ")))" ) ) ;
37+ assert_eq ! ( "-3" , Day01 . part_one( ")())())" ) ) ;
2538 }
2639}
0 commit comments