File tree Expand file tree Collapse file tree 2 files changed +23
-3
lines changed
Expand file tree Collapse file tree 2 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 8787
8888| Day | Solved | Part 1 time (ms) | Part 2 time (ms) |
8989| ----------------------------------------------------------| :------:| -----------------:| -----------------:|
90- | [ Day 1: Not Quite Lisp] ( src/solutions/year2015/day01.rs ) | ⭐ | 0.013 | - |
90+ | [ Day 1: Not Quite Lisp] ( src/solutions/year2015/day01.rs ) | ⭐⭐ | 0.013 | 0.001 |
9191
9292# TODO
9393
Original file line number Diff line number Diff line change @@ -15,8 +15,22 @@ impl Solution for Day01 {
1515 . to_string ( )
1616 }
1717
18- fn part_two ( & self , _input : & str ) -> String {
19- String :: from ( "0" )
18+ fn part_two ( & self , input : & str ) -> String {
19+ let mut current_flor = 0 ;
20+
21+ for ( i, b) in input. bytes ( ) . enumerate ( ) {
22+ current_flor += match b {
23+ b'(' => 1 ,
24+ b')' => -1 ,
25+ _ => 0 ,
26+ } ;
27+
28+ if current_flor == -1 {
29+ return ( i + 1 ) . to_string ( ) ;
30+ }
31+ }
32+
33+ unreachable ! ( )
2034 }
2135}
2236
@@ -36,4 +50,10 @@ mod tests {
3650 assert_eq ! ( "-3" , Day01 . part_one( ")))" ) ) ;
3751 assert_eq ! ( "-3" , Day01 . part_one( ")())())" ) ) ;
3852 }
53+
54+ #[ test]
55+ fn part_two_example_test ( ) {
56+ assert_eq ! ( "1" , Day01 . part_two( ")" ) ) ;
57+ assert_eq ! ( "5" , Day01 . part_two( "()())" ) ) ;
58+ }
3959}
You can’t perform that action at this time.
0 commit comments