This commit is contained in:
Daniel Flanagan 2022-12-05 23:28:27 -06:00
parent 7a2db9ae56
commit a117350190
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -2,11 +2,14 @@ mod common;
use std::collections::HashSet; use std::collections::HashSet;
type Input = str; type Input = Vec<char>;
type Result = usize; type Result = usize;
fn part1(input: &Input) -> Result { fn processed_input(input: &str) -> Vec<char> {
let c: Vec<char> = input.chars().collect(); input.chars().collect()
}
fn part1(c: &Input) -> Result {
for i in 3.. { for i in 3.. {
if c[i] != c[i - 1] if c[i] != c[i - 1]
&& c[i] != c[i - 2] && c[i] != c[i - 2]
@ -22,8 +25,7 @@ fn part1(input: &Input) -> Result {
0 0
} }
fn part2(input: &Input) -> Result { fn part2(c: &Input) -> Result {
let c: Vec<char> = input.chars().collect();
for i in 13..c.len() { for i in 13..c.len() {
let mut s: HashSet<char> = HashSet::new(); let mut s: HashSet<char> = HashSet::new();
for j in i - 13..=i { for j in i - 13..=i {
@ -39,7 +41,8 @@ fn part2(input: &Input) -> Result {
fn main() { fn main() {
let input_text = common::day_input(6); 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)] #[cfg(test)]
@ -50,8 +53,9 @@ mod tests {
#[test] #[test]
fn test() { fn test() {
let input = TEST_INPUT; let input_text = TEST_INPUT;
assert_eq!(part1(input), 7); let input = processed_input(&input_text);
assert_eq!(part2(input), 19); assert_eq!(part1(&input), 7);
assert_eq!(part2(&input), 19);
} }
} }