diff --git a/2022/rust/src/day6.rs b/2022/rust/src/day6.rs index 59dcb32..91a7dec 100644 --- a/2022/rust/src/day6.rs +++ b/2022/rust/src/day6.rs @@ -2,11 +2,14 @@ mod common; use std::collections::HashSet; -type Input = str; +type Input = Vec; type Result = usize; -fn part1(input: &Input) -> Result { - let c: Vec = input.chars().collect(); +fn processed_input(input: &str) -> Vec { + input.chars().collect() +} + +fn part1(c: &Input) -> Result { for i in 3.. { if c[i] != c[i - 1] && c[i] != c[i - 2] @@ -22,8 +25,7 @@ fn part1(input: &Input) -> Result { 0 } -fn part2(input: &Input) -> Result { - let c: Vec = input.chars().collect(); +fn part2(c: &Input) -> Result { for i in 13..c.len() { let mut s: HashSet = HashSet::new(); for j in i - 13..=i { @@ -39,7 +41,8 @@ fn part2(input: &Input) -> Result { fn main() { let input_text = common::day_input(6); - common::show_answers(&part1(&input_text), &part2(&input_text)) + let input = processed_input(&input_text); + common::show_answers(&part1(&input), &part2(&input)) } #[cfg(test)] @@ -50,8 +53,9 @@ mod tests { #[test] fn test() { - let input = TEST_INPUT; - assert_eq!(part1(input), 7); - assert_eq!(part2(input), 19); + let input_text = TEST_INPUT; + let input = processed_input(&input_text); + assert_eq!(part1(&input), 7); + assert_eq!(part2(&input), 19); } }