Skip to content

Commit 6d301ca

Browse files
committed
Use array ref instead of Vec ref in day 2
1 parent c6e6901 commit 6d301ca

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/bin/02.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use itertools::Itertools;
33

44
advent_of_code::solution!(2);
55

6-
fn is_safe(data: &Vec<u32>) -> bool {
6+
fn is_safe(data: &[u32]) -> bool {
77
let direction = data[0].cmp(&data[1]);
88
if direction == Equal {
99
return false;
@@ -13,12 +13,12 @@ fn is_safe(data: &Vec<u32>) -> bool {
1313
.all(|valid| valid)
1414
}
1515

16-
fn is_safe_lenient(data: &Vec<u32>) -> bool {
16+
fn is_safe_lenient(data: &[u32]) -> bool {
1717
if is_safe(data) {
1818
return true;
1919
}
2020
(0..data.len()).any(|index| {
21-
let mut modified_data = data.clone();
21+
let mut modified_data = data.to_vec();
2222
modified_data.remove(index);
2323
is_safe(&modified_data)
2424
})
@@ -37,11 +37,11 @@ where
3737
}
3838

3939
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)))
4141
}
4242

4343
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)))
4545
}
4646

4747
#[cfg(test)]

0 commit comments

Comments
 (0)