uploading 2022 where i left it

This commit is contained in:
Dylan Thies
2023-12-07 08:24:18 -05:00
parent 2d37c34122
commit 6eaaa4630e
5 changed files with 126 additions and 0 deletions

8
Cargo.lock generated
View File

@@ -62,6 +62,14 @@ dependencies = [
"nom",
]
[[package]]
name = "day17"
version = "2022.0.0"
dependencies = [
"itertools",
"nom",
]
[[package]]
name = "day2"
version = "2022.0.0"

View File

@@ -16,6 +16,7 @@ members = [
"day14",
"day15",
"day16",
"day17",
]
resolver = "2"

12
day17/Cargo.toml Normal file
View File

@@ -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

59
day17/src/main.rs Normal file
View File

@@ -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::Item> {
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::<Vec<_>>();
println!("{shapes:#?}");
}

View File

@@ -119,6 +119,14 @@ fn recurse_part1(collector: &mut Vec<usize>, 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");
}
}