fspoettel / advent-of-code-rust

πŸŽ„Starter template for solving Advent of Code in Rust.
MIT License
715 stars 53 forks source link

RFC: Separate parsing from solutions? #15

Closed fspoettel closed 1 year ago

fspoettel commented 2 years ago

Implementation

Currently experimenting with a separately timed parser util on my solution repo, might add to template after this year concludes.

Advantages:

Disadvantages:

type Input<'a> = Vec<&'a str>;

fn parse(input: &str) -> Input {
    input.lines().collect()
}

pub fn part_one(input: Input) -> Option<u32> {
    None
}

pub fn part_two(input: Input) -> Option<u32> {
    None
}

advent_of_code::main!(4);

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_part_one() {
        let input = advent_of_code::read_file("examples", 4);
        assert_eq!(part_one(parse(&input)), None);
    }

    #[test]
    fn test_part_two() {
        let input = advent_of_code::read_file("examples", 4);
        assert_eq!(part_two(parse(&input)), None);
    }
}

Example output:

πŸŽ„ Parser πŸŽ„
(elapsed: 24.96Β΅s)
πŸŽ„ Part 1 πŸŽ„
13005 (elapsed: 6.00ns)
πŸŽ„ Part 2 πŸŽ„
11373 (elapsed: 831.00ns)
aranasaurus commented 2 years ago

I like this idea. I think the disadvantage you listed might be able to be addressed, at least partially by adding something to the README. Step by step example how to change it for one, and then possibly a link to some documentation about the syntax and how it works?