diff --git a/Cargo.lock b/Cargo.lock index 66ab1b5..102e0fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,14 @@ dependencies = [ "nom", ] +[[package]] +name = "day17" +version = "2022.0.0" +dependencies = [ + "itertools", + "nom", +] + [[package]] name = "day2" version = "2022.0.0" diff --git a/Cargo.toml b/Cargo.toml index cf89bfb..ebf9b0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ members = [ "day14", "day15", "day16", + "day17", ] resolver = "2" diff --git a/day17/Cargo.toml b/day17/Cargo.toml new file mode 100644 index 0000000..50a9f43 --- /dev/null +++ b/day17/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "day17" +version.workspace = true +edition.workspace = true +authors.workspace = true +repository.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +itertools.workspace = true +nom.workspace = true diff --git a/day17/src/main.rs b/day17/src/main.rs new file mode 100644 index 0000000..b44409c --- /dev/null +++ b/day17/src/main.rs @@ -0,0 +1,59 @@ +use std::default; + +use nom::{branch::alt, bytes::complete::tag, error::Error, Parser}; + +#[derive(Debug, Clone, Copy)] +enum Shape { + Bar, + Plus, + El, + Staff, + Square, +} + +impl Shape { + pub fn iter() -> ShapeGenerator { + ShapeGenerator::new() + } +} + +struct ShapeGenerator { + last_shape: Shape, +} +impl ShapeGenerator { + fn new() -> Self { + Self { + last_shape: Shape::Square, + } + } +} + +impl Iterator for ShapeGenerator { + type Item = Shape; + + fn next(&mut self) -> Option { + self.last_shape = match self.last_shape { + Shape::Bar => Shape::Plus, + Shape::Plus => Shape::El, + Shape::El => Shape::Staff, + Shape::Staff => Shape::Square, + Shape::Square => Shape::Bar, + }; + Some(self.last_shape) + } +} + +enum Jet { + Left, + Right, +} + +impl<'a> Parser<&'a str, Self, Error<&'a str>> for Jet { + fn parse(&mut self, input: &'a str) -> nom::IResult<&'a str, Self, Error<&'a str>> { + alt((tag("<").map(|_| Self::Left), tag(">").map(|_| Self::Right)))(input) + } +} +fn main() { + let shapes = Shape::iter().take(10).collect::>(); + println!("{shapes:#?}"); +} diff --git a/day7/src/main.rs b/day7/src/main.rs index 24e5e7c..7a23af8 100644 --- a/day7/src/main.rs +++ b/day7/src/main.rs @@ -119,6 +119,14 @@ fn recurse_part1(collector: &mut Vec, cwd: &MyDir) -> usize { cwd_size } +fn process_part1(input: &str) -> String { + todo!() +} + +fn process_part2(input: &str) -> String { + todo!() +} + fn main() -> std::io::Result<()> { //Read in file let file = File::open("input")?; @@ -172,3 +180,41 @@ fn main() -> std::io::Result<()> { println!("Part 2: {}", part2.unwrap()); Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + const INPUT: &str = "$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k"; + #[test] + fn part1_works() { + assert_eq!(process_part1(INPUT), "95437"); + } + + #[test] + fn part2_works() { + assert_eq!(process_part2(INPUT), "24933642"); + } +}