File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed
Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change 9494| [ Day 5: Doesn't He Have Intern-Elves For This?] ( src/solutions/year2015/day05.rs ) | ⭐⭐ | 0.261 | 0.987 |
9595| [ Day 6: Probably a Fire Hazard] ( src/solutions/year2015/day06.rs ) | ⭐⭐ | 871.538 | 817.533 |
9696| [ Day 7: Some Assembly Required] ( src/solutions/year2015/day07.rs ) | ⭐⭐ | 0.308 | 0.293 |
97+ | [ Day 8: Matchsticks] ( src/solutions/year2015/day08.rs ) | ⭐ | 0.171 | - |
9798
9899# TODO
99100
Original file line number Diff line number Diff line change @@ -3,8 +3,36 @@ use crate::solutions::Solution;
33pub struct Day08 ;
44
55impl Solution for Day08 {
6- fn part_one ( & self , _input : & str ) -> String {
7- String :: from ( "0" )
6+ fn part_one ( & self , input : & str ) -> String {
7+ input
8+ . lines ( )
9+ . map ( |l| {
10+ let mut i: usize = 1 ;
11+ let len = l. len ( ) ;
12+ let mut characters: usize = 0 ;
13+
14+ loop {
15+ if i == len - 1 {
16+ break ;
17+ }
18+
19+ if l. chars ( ) . nth ( i) . unwrap ( ) == '\\' {
20+ if l. chars ( ) . nth ( i + 1 ) . unwrap ( ) == 'x' {
21+ i += 3 ;
22+ } else {
23+ i += 1 ;
24+ }
25+ }
26+
27+ characters += 1 ;
28+
29+ i += 1 ;
30+ }
31+
32+ len - characters
33+ } )
34+ . sum :: < usize > ( )
35+ . to_string ( )
836 }
937
1038 fn part_two ( & self , _input : & str ) -> String {
@@ -18,6 +46,9 @@ mod tests {
1846
1947 #[ test]
2048 fn part_one_example_test ( ) {
21- assert_eq ! ( "0" , Day08 . part_one( "0" ) ) ;
49+ assert_eq ! ( "2" , Day08 . part_one( "\" \" " ) ) ;
50+ assert_eq ! ( "2" , Day08 . part_one( "\" abc\" " ) ) ;
51+ assert_eq ! ( "3" , Day08 . part_one( "\" aaa\\ \" aaa\" " ) ) ;
52+ assert_eq ! ( "5" , Day08 . part_one( "\" \\ x27\" " ) ) ;
2253 }
2354}
You can’t perform that action at this time.
0 commit comments