diff --git a/.gitignore b/.gitignore index 6969c26..d8b824c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,3 @@ target/ # downloaded inputs /src/inputs/* !/src/inputs/.keep - -/src/test_inputs/* -!/src/test_inputs/.keep diff --git a/src/bin/01.rs b/src/bin/01.rs index c9cbd71..d30c8f6 100644 --- a/src/bin/01.rs +++ b/src/bin/01.rs @@ -1,14 +1,14 @@ pub fn part_one(input: &str) -> Option { let count = input.matches('(').count() - input.matches(')').count(); - Some(count.try_into().unwrap()) + Some(count as u32) } pub fn part_two(input: &str) -> Option { let mut floor = 0; - for (idx, char) in input.chars().enumerate() { - match char { + for (idx, c) in input.trim().chars().enumerate() { + match c { '(' => floor += 1, ')' => floor -= 1, - _ => panic!("oops"), + _ => panic!("oops {}", c), }; if floor < 0 { @@ -27,14 +27,12 @@ mod tests { use super::*; #[test] fn test_part_one() { - // let input = aoc::read_file("test_inputs", 1); - let input = "(()(()("; + let input = aoc::read_file("test_inputs", 1); assert_eq!(part_one(&input), Some(3)); } #[test] fn test_part_two() { - // let input = aoc::read_file("test_inputs", 1); - let input = "()())"; - assert_eq!(part_two(&input), Some(5)); + let input = aoc::read_file("test_inputs", 1); + assert_eq!(part_two(&input), Some(11)); } } diff --git a/src/bin/02.rs b/src/bin/02.rs index 610099e..a8d0e94 100644 --- a/src/bin/02.rs +++ b/src/bin/02.rs @@ -42,14 +42,12 @@ mod tests { use super::*; #[test] fn test_part_one() { - // let input = aoc::read_file("test_inputs", 2); - let input = "2x3x4"; + let input = aoc::read_file("test_inputs", 2); assert_eq!(part_one(&input), Some(58)); } #[test] fn test_part_two() { - // let input = aoc::read_file("test_inputs", 2); - let input = "2x3x4"; + let input = aoc::read_file("test_inputs", 2); assert_eq!(part_two(&input), Some(34)); } } diff --git a/src/bin/03.rs b/src/bin/03.rs index 0924740..d150356 100644 --- a/src/bin/03.rs +++ b/src/bin/03.rs @@ -53,14 +53,12 @@ mod tests { use super::*; #[test] fn test_part_one() { - // let input = aoc::read_file("test_inputs", 3); - let input = "^v^v^v^v^v"; + let input = aoc::read_file("test_inputs", 3); assert_eq!(part_one(&input), Some(2)); } #[test] fn test_part_two() { - // let input = aoc::read_file("test_inputs", 3); - let input = "^v^v^v^v^v"; + let input = aoc::read_file("test_inputs", 3); assert_eq!(part_two(&input), Some(11)); } } diff --git a/src/bin/04.rs b/src/bin/04.rs index 52a2bda..fe7f775 100644 --- a/src/bin/04.rs +++ b/src/bin/04.rs @@ -44,14 +44,12 @@ mod tests { use super::*; #[test] fn test_part_one() { - // let input = aoc::read_file("test_inputs", 4); - let input = "abcdef"; + let input = aoc::read_file("test_inputs", 4); assert_eq!(part_one(&input), Some(609043)); } #[test] fn test_part_two() { - // let input = aoc::read_file("test_inputs", 4); - // let input = "abcdef"; - // assert_eq!(part_two(&input), None); + let input = aoc::read_file("test_inputs", 4); + assert_eq!(part_two(&input), Some(6742839)); } } diff --git a/src/bin/05.rs b/src/bin/05.rs index 58092bd..5b9a8c6 100644 --- a/src/bin/05.rs +++ b/src/bin/05.rs @@ -64,15 +64,12 @@ mod tests { use super::*; #[test] fn test_part_one() { - // let input = aoc::read_file("test_inputs", 5); - let input = "aaa"; + let input = aoc::read_file("test_inputs", 5); assert_eq!(part_one(&input), Some(1)); } #[test] fn test_part_two() { - // let input = aoc::read_file("test_inputs", 5); - let input = - "qjhvhtzxzqqjkmpb\nxxyxx\nuurcxstgmygtbstg\nieodomkazucvgmuy\naaa"; + let input = aoc::read_file("test_inputs", 5); assert_eq!(part_two(&input), Some(2)); } } diff --git a/src/test_inputs/01.txt b/src/test_inputs/01.txt new file mode 100644 index 000000000..db6e957 --- /dev/null +++ b/src/test_inputs/01.txt @@ -0,0 +1 @@ +(()(()())))(((( diff --git a/src/test_inputs/02.txt b/src/test_inputs/02.txt new file mode 100644 index 000000000..5256b38 --- /dev/null +++ b/src/test_inputs/02.txt @@ -0,0 +1 @@ +2x3x4 diff --git a/src/test_inputs/03.txt b/src/test_inputs/03.txt new file mode 100644 index 000000000..8a6e322 --- /dev/null +++ b/src/test_inputs/03.txt @@ -0,0 +1 @@ +^v^v^v^v^v diff --git a/src/test_inputs/04.txt b/src/test_inputs/04.txt new file mode 100644 index 000000000..0373d93 --- /dev/null +++ b/src/test_inputs/04.txt @@ -0,0 +1 @@ +abcdef diff --git a/src/test_inputs/05.txt b/src/test_inputs/05.txt new file mode 100644 index 000000000..a91e7c2 --- /dev/null +++ b/src/test_inputs/05.txt @@ -0,0 +1,5 @@ +qjhvhtzxzqqjkmpb +xxyxx +uurcxstgmygtbstg +ieodomkazucvgmuy +aaa