Cleanup
This commit is contained in:
parent
7a2db9ae56
commit
a117350190
|
@ -2,11 +2,14 @@ mod common;
|
|||
|
||||
use std::collections::HashSet;
|
||||
|
||||
type Input = str;
|
||||
type Input = Vec<char>;
|
||||
type Result = usize;
|
||||
|
||||
fn part1(input: &Input) -> Result {
|
||||
let c: Vec<char> = input.chars().collect();
|
||||
fn processed_input(input: &str) -> Vec<char> {
|
||||
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<char> = input.chars().collect();
|
||||
fn part2(c: &Input) -> Result {
|
||||
for i in 13..c.len() {
|
||||
let mut s: HashSet<char> = 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue