This commit is contained in:
nora 2023-12-03 13:00:23 +01:00
parent c59b21ebc7
commit b093225df0
3 changed files with 102 additions and 22 deletions

View file

@ -1,3 +1,4 @@
use helper::{Day, Variants};
use nom::{
branch::alt,
bytes::complete::tag,
@ -24,6 +25,18 @@ fn main() {
println!("result: {result}");
}
struct Day4;
impl Day for Day4 {
fn part1() -> helper::Variants {
Variants::basic(part1)
}
fn part2() -> helper::Variants {
Variants::basic(part2)
}
}
#[derive(Debug, Clone, Copy)]
enum Color {
Red = 0,
@ -90,22 +103,21 @@ fn part2(input: &str) -> u64 {
#[cfg(test)]
mod tests {
#[test]
fn part1_small() {
assert_eq!(super::part1(include_str!("../input_small.txt")), 8);
}
#[test]
fn part1() {
assert_eq!(super::part1(include_str!("../input.txt")), 1931);
helper::test_part1::<super::Day4>(&[
(include_str!("../input_small.txt"), 8),
(include_str!("../input.txt"), 1931),
]
);
}
#[test]
fn part2_small() {
assert_eq!(super::part2(include_str!("../input_small.txt")), 2286);
}
#[test]
fn part2() {
assert_eq!(super::part2(include_str!("../input.txt")), 83105);
helper::test_part2::<super::Day4>(&[
(include_str!("../input_small.txt"), 2286),
(include_str!("../input.txt"), 83105),
]
);
}
}

View file

@ -1,5 +1,7 @@
use std::collections::HashMap;
use helper::{Day, Variants};
fn main() {
let kind = std::env::args().nth(1).unwrap_or("naive".into());
@ -17,6 +19,18 @@ fn main() {
println!("result: {result}");
}
struct Day3;
impl Day for Day3 {
fn part1() -> Variants {
Variants::basic(part1)
}
fn part2() -> Variants {
Variants::basic(part2)
}
}
fn part1(input: &str) -> u64 {
fn contains_symbol(s: &str) -> bool {
s.chars().any(|c| !c.is_ascii_digit() && c != '.')
@ -118,22 +132,21 @@ fn part2(input: &str) -> u64 {
#[cfg(test)]
mod tests {
#[test]
fn part1_small() {
assert_eq!(super::part1(include_str!("../input_small.txt")), 4361);
}
#[test]
fn part1() {
assert_eq!(super::part1(include_str!("../input.txt")), 537832);
helper::test_part1::<super::Day3>(&[
(include_str!("../input_small.txt"), 4361),
(include_str!("../input.txt"), 537832),
]
);
}
#[test]
fn part2_small() {
assert_eq!(super::part2(include_str!("../input_small.txt")), 467835);
}
#[test]
fn part2() {
assert_eq!(super::part2(include_str!("../input.txt")), 81939900);
helper::test_part2::<super::Day3>(&[
(include_str!("../input_small.txt"), 467835),
(include_str!("../input.txt"), 81939900),
]
);
}
}