File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ use itertools::Itertools;
3
3
4
4
advent_of_code:: solution!( 2 ) ;
5
5
6
- fn is_safe ( data : & Vec < u32 > ) -> bool {
6
+ fn is_safe ( data : & [ u32 ] ) -> bool {
7
7
let direction = data[ 0 ] . cmp ( & data[ 1 ] ) ;
8
8
if direction == Equal {
9
9
return false ;
@@ -13,12 +13,12 @@ fn is_safe(data: &Vec<u32>) -> bool {
13
13
. all ( |valid| valid)
14
14
}
15
15
16
- fn is_safe_lenient ( data : & Vec < u32 > ) -> bool {
16
+ fn is_safe_lenient ( data : & [ u32 ] ) -> bool {
17
17
if is_safe ( data) {
18
18
return true ;
19
19
}
20
20
( 0 ..data. len ( ) ) . any ( |index| {
21
- let mut modified_data = data. clone ( ) ;
21
+ let mut modified_data = data. to_vec ( ) ;
22
22
modified_data. remove ( index) ;
23
23
is_safe ( & modified_data)
24
24
} )
@@ -37,11 +37,11 @@ where
37
37
}
38
38
39
39
pub fn part_one ( input : & str ) -> Option < u32 > {
40
- Some ( count_safe_reports ( input, is_safe) )
40
+ Some ( count_safe_reports ( input, |data| is_safe ( data ) ) )
41
41
}
42
42
43
43
pub fn part_two ( input : & str ) -> Option < u32 > {
44
- Some ( count_safe_reports ( input, is_safe_lenient) )
44
+ Some ( count_safe_reports ( input, |data| is_safe_lenient ( data ) ) )
45
45
}
46
46
47
47
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments