Compare commits

...

10 Commits

Author SHA1 Message Date
Dylan Thies
951cab12f3 2024 day-6 part one submitted no clippy 2024-12-06 10:26:48 -05:00
Dylan Thies
fb33e62a56 setting up for 2024 day 6 and fixing some of the comments 2024-12-05 16:23:47 -05:00
Dylan Thies
25dedc74fa 2024 day-5 clippy and done 2024-12-05 16:13:13 -05:00
Dylan Thies
d320036973 clippy for 2024 day-4 2024-12-04 21:00:58 -05:00
Dylan Thies
fdb74e6439 2024 day-4 as completed 2024-12-04 08:45:57 -05:00
Dylan Thies
17e5f32800 2024 day 3 clippy of original solution 2024-12-03 13:33:40 -05:00
Dylan Thies
2e7cda7aa3 2024 day-3 as answered 2024-12-03 13:00:11 -05:00
Dylan Thies
cd22838062 decided to clippy 2023 in 2024 2024-12-02 11:49:26 -05:00
Dylan Thies
0e93372b96 why where these changed no one knows but past me 2024-12-02 11:29:22 -05:00
Dylan Thies
0ceb59d424 adding Cargo lock 2024-12-02 11:27:59 -05:00
36 changed files with 2049 additions and 67 deletions

View File

@@ -82,7 +82,6 @@ fn main() -> std::io::Result<()> {
} else { } else {
0 0
}; };
// println!("Right: {}, {:?}", right_score, right_part);
let left_part = board[y].iter().rev().skip(x_inv).collect::<Vec<_>>(); let left_part = board[y].iter().rev().skip(x_inv).collect::<Vec<_>>();
let left_score = if left_part.len() > 1 { let left_score = if left_part.len() > 1 {
let score = left_part let score = left_part
@@ -99,7 +98,6 @@ fn main() -> std::io::Result<()> {
} else { } else {
0 0
}; };
// println!("Left: {}, {:?}", left_score, left_part);
let down_part = board.iter().map(|row| row[x]).skip(y).collect::<Vec<_>>(); let down_part = board.iter().map(|row| row[x]).skip(y).collect::<Vec<_>>();
let down_score = if down_part.len() > 1 { let down_score = if down_part.len() > 1 {
let score = down_part let score = down_part
@@ -116,7 +114,6 @@ fn main() -> std::io::Result<()> {
} else { } else {
0 0
}; };
// println!("Down: {}, {:?}", down_score, down_part);
let up_part = board let up_part = board
.iter() .iter()
.map(|row| row[x]) .map(|row| row[x])
@@ -138,12 +135,7 @@ fn main() -> std::io::Result<()> {
} else { } else {
0 0
}; };
// println!("Up: {}. {:?}", up_score, up_part);
let tree_score = right_score * left_score * down_score * up_score; let tree_score = right_score * left_score * down_score * up_score;
// println!(
// "({}, {})({}) = {} = {} * {} * {} * {}",
// x, y, tree_from_top_left, tree_score, up_score, left_score, down_score, right_score
// );
scores[y][x] = tree_score; scores[y][x] = tree_score;
} }
} }

2
2023/Cargo.lock generated
View File

@@ -274,6 +274,7 @@ dependencies = [
name = "day-21" name = "day-21"
version = "2023.0.0" version = "2023.0.0"
dependencies = [ dependencies = [
"dhat",
"glam", "glam",
"itertools 0.12.0", "itertools 0.12.0",
"nom", "nom",
@@ -285,6 +286,7 @@ dependencies = [
name = "day-22" name = "day-22"
version = "2023.0.0" version = "2023.0.0"
dependencies = [ dependencies = [
"dhat",
"glam", "glam",
"itertools 0.12.0", "itertools 0.12.0",
"nom", "nom",

View File

@@ -23,13 +23,13 @@ impl Drawing {
.iter() .iter()
.filter(|mound| mound.x + span >= reflect_col && mound.x < reflect_col) .filter(|mound| mound.x + span >= reflect_col && mound.x < reflect_col)
.map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into()) .map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into())
.all(|mound_reflect| self.mounds.get(&mound_reflect).is_some()) .all(|mound_reflect| self.mounds.contains(&mound_reflect))
&& self && self
.mounds .mounds
.iter() .iter()
.filter(|mound| mound.x < reflect_col + span && mound.x >= reflect_col) .filter(|mound| mound.x < reflect_col + span && mound.x >= reflect_col)
.map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into()) .map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into())
.all(|mound_reflect| self.mounds.get(&mound_reflect).is_some()) .all(|mound_reflect| self.mounds.contains(&mound_reflect))
}) })
.sum::<u32>(); .sum::<u32>();
let row_score = (1..max_row) let row_score = (1..max_row)
@@ -40,13 +40,13 @@ impl Drawing {
.iter() .iter()
.filter(|mound| mound.y + span >= reflect_row && mound.y < reflect_row) .filter(|mound| mound.y + span >= reflect_row && mound.y < reflect_row)
.map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into()) .map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into())
.all(|mound_reflect| self.mounds.get(&mound_reflect).is_some()) .all(|mound_reflect| self.mounds.contains(&mound_reflect))
&& self && self
.mounds .mounds
.iter() .iter()
.filter(|mound| mound.y < reflect_row + span && mound.y >= reflect_row) .filter(|mound| mound.y < reflect_row + span && mound.y >= reflect_row)
.map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into()) .map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into())
.all(|mound_reflect| self.mounds.get(&mound_reflect).is_some()) .all(|mound_reflect| self.mounds.contains(&mound_reflect))
}) })
.sum::<u32>() .sum::<u32>()
* 100; * 100;

View File

@@ -24,14 +24,14 @@ impl Drawing {
.iter() .iter()
.filter(|mound| mound.x + span >= reflect_col && mound.x < reflect_col) .filter(|mound| mound.x + span >= reflect_col && mound.x < reflect_col)
.map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into()) .map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into())
.filter(|mound_reflect| self.mounds.get(mound_reflect).is_none()) .filter(|mound_reflect| !self.mounds.contains(mound_reflect))
.count() .count()
+ self + self
.mounds .mounds
.iter() .iter()
.filter(|mound| mound.x < reflect_col + span && mound.x >= reflect_col) .filter(|mound| mound.x < reflect_col + span && mound.x >= reflect_col)
.map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into()) .map(|mound| (2 * reflect_col - mound.x - 1, mound.y).into())
.filter(|mound_reflect| self.mounds.get(mound_reflect).is_none()) .filter(|mound_reflect| !self.mounds.contains(mound_reflect))
.count()) .count())
== 1 == 1
}) })
@@ -45,14 +45,14 @@ impl Drawing {
.iter() .iter()
.filter(|mound| mound.y + span >= reflect_row && mound.y < reflect_row) .filter(|mound| mound.y + span >= reflect_row && mound.y < reflect_row)
.map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into()) .map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into())
.filter(|mound_reflect| self.mounds.get(mound_reflect).is_none()) .filter(|mound_reflect| !self.mounds.contains(mound_reflect))
.count() .count()
+ self + self
.mounds .mounds
.iter() .iter()
.filter(|mound| mound.y < reflect_row + span && mound.y >= reflect_row) .filter(|mound| mound.y < reflect_row + span && mound.y >= reflect_row)
.map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into()) .map(|mound| (mound.x, 2 * reflect_row - mound.y - 1).into())
.filter(|mound_reflect| self.mounds.get(mound_reflect).is_none()) .filter(|mound_reflect| !self.mounds.contains(mound_reflect))
.count()) .count())
== 1 == 1
}) })

View File

@@ -57,11 +57,12 @@ pub fn part2(input: &str) -> String {
let pos_in_cycle = start_of_cycle + (cycles - end_of_cycle) % len_of_cyle; let pos_in_cycle = start_of_cycle + (cycles - end_of_cycle) % len_of_cyle;
map = cache map.clone_from(
cache
.values() .values()
.find_map(|(look_at_map, pos)| (*pos == pos_in_cycle).then_some(look_at_map)) .find_map(|(look_at_map, pos)| (*pos == pos_in_cycle).then_some(look_at_map))
.unwrap() .unwrap(),
.clone(); );
let mut total = 0_usize; let mut total = 0_usize;
for col in 0..maxes.x { for col in 0..maxes.x {

View File

@@ -18,9 +18,9 @@ pub enum Day2Part1Error {
#[derive(Debug)] #[derive(Debug)]
struct Round { struct Round {
pub red_n: u32, pub red: u32,
pub green_n: u32, pub green: u32,
pub blue_n: u32, pub blue: u32,
} }
#[derive(Debug)] #[derive(Debug)]
@@ -35,7 +35,7 @@ impl Game {
.iter() .iter()
.find_map(|r| { .find_map(|r| {
//TODO if inverted use find_map //TODO if inverted use find_map
if r.red_n > 12 || r.green_n > 13 || r.blue_n > 14 { if r.red > 12 || r.green > 13 || r.blue > 14 {
Some(self.id) Some(self.id)
} else { } else {
None None
@@ -74,15 +74,15 @@ fn process_block(input: &str) -> nom::IResult<&str, (u32, String)> {
fn process_round(input: &str) -> nom::IResult<&str, Round> { fn process_round(input: &str) -> nom::IResult<&str, Round> {
let (i, blocks) = separated_list1(tag(", "), process_block)(input)?; let (i, blocks) = separated_list1(tag(", "), process_block)(input)?;
let mut round = Round { let mut round = Round {
red_n: 0, red: 0,
green_n: 0, green: 0,
blue_n: 0, blue: 0,
}; };
for (cnt, color) in blocks { for (cnt, color) in blocks {
match color.as_str() { match color.as_str() {
"red" => round.red_n = cnt, "red" => round.red = cnt,
"green" => round.green_n = cnt, "green" => round.green = cnt,
"blue" => round.blue_n = cnt, "blue" => round.blue = cnt,
_ => panic!("this should be a color name"), _ => panic!("this should be a color name"),
}; };
} }

View File

@@ -17,9 +17,9 @@ pub enum Day2Part2Error {
#[derive(Debug)] #[derive(Debug)]
struct Round { struct Round {
pub red_n: u32, pub red: u32,
pub green_n: u32, pub green: u32,
pub blue_n: u32, pub blue: u32,
} }
#[derive(Debug)] #[derive(Debug)]
@@ -32,14 +32,14 @@ impl Game {
fn to_power(&self) -> u64 { fn to_power(&self) -> u64 {
let (r, g, b) = self.rounds.iter().fold((0_u64, 0_u64, 0_u64), |acc, x| { let (r, g, b) = self.rounds.iter().fold((0_u64, 0_u64, 0_u64), |acc, x| {
let (mut val_r, mut val_g, mut val_b) = acc; let (mut val_r, mut val_g, mut val_b) = acc;
if u64::from(x.red_n) > acc.0 { if u64::from(x.red) > acc.0 {
val_r = x.red_n.into(); val_r = x.red.into();
} }
if u64::from(x.green_n) > acc.1 { if u64::from(x.green) > acc.1 {
val_g = x.green_n.into(); val_g = x.green.into();
} }
if u64::from(x.blue_n) > acc.2 { if u64::from(x.blue) > acc.2 {
val_b = x.blue_n.into(); val_b = x.blue.into();
} }
(val_r, val_g, val_b) (val_r, val_g, val_b)
}); });
@@ -70,15 +70,15 @@ fn process_block(input: &str) -> nom::IResult<&str, (u32, String)> {
fn process_round(input: &str) -> nom::IResult<&str, Round> { fn process_round(input: &str) -> nom::IResult<&str, Round> {
let (i, blocks) = separated_list1(tag(", "), process_block)(input)?; let (i, blocks) = separated_list1(tag(", "), process_block)(input)?;
let mut round = Round { let mut round = Round {
red_n: 0, red: 0,
green_n: 0, green: 0,
blue_n: 0, blue: 0,
}; };
for (cnt, color) in blocks { for (cnt, color) in blocks {
match color.as_str() { match color.as_str() {
"red" => round.red_n = cnt, "red" => round.red = cnt,
"green" => round.green_n = cnt, "green" => round.green = cnt,
"blue" => round.blue_n = cnt, "blue" => round.blue = cnt,
_ => panic!("this should be a color name"), _ => panic!("this should be a color name"),
}; };
} }

View File

@@ -12,6 +12,10 @@ nom = { workspace = true }
itertools = {workspace = true } itertools = {workspace = true }
nom_locate.workspace = true nom_locate.workspace = true
glam.workspace = true glam.workspace = true
dhat = { workspace = true }
[dev-dependencies] [dev-dependencies]
rstest.workspace = true rstest.workspace = true
[features]
dhat-heap = []

View File

@@ -3,7 +3,14 @@
use day_21::part1; use day_21::part1;
use day_21::part2; use day_21::part2;
#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
fn main() { fn main() {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();
let input = include_str!("./input.txt"); let input = include_str!("./input.txt");
let part1_result = part1(input, 64); let part1_result = part1(input, 64);
println!("part 1: {part1_result}"); println!("part 1: {part1_result}");

View File

@@ -11,3 +11,7 @@ repository.workspace = true
nom = { workspace = true } nom = { workspace = true }
itertools = {workspace = true } itertools = {workspace = true }
glam.workspace = true glam.workspace = true
dhat = { workspace = true }
[features]
dhat-heap = []

View File

@@ -3,7 +3,14 @@
use day_22::part1; use day_22::part1;
use day_22::part2; use day_22::part2;
#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
fn main() { fn main() {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();
let input = include_str!("./input.txt"); let input = include_str!("./input.txt");
let part1_result = part1(input); let part1_result = part1(input);
println!("part 1: {part1_result}"); println!("part 1: {part1_result}");

View File

@@ -60,8 +60,7 @@ pub fn part1(input: &str) -> String {
.filter_map(|dir| { .filter_map(|dir| {
let next_pos = dir + *pos; let next_pos = dir + *pos;
node_map node_map
.get(&next_pos) .contains_key(&next_pos)
.is_some()
.then(|| (node_map[pos], node_map[&next_pos], 1)) .then(|| (node_map[pos], node_map[&next_pos], 1))
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()

View File

@@ -47,8 +47,7 @@ pub fn part2(input: &str) -> String {
.filter_map(|dir| { .filter_map(|dir| {
let next_pos = dir + *pos; let next_pos = dir + *pos;
node_map node_map
.get(&next_pos) .contains_key(&next_pos)
.is_some()
.then(|| (node_map[pos], node_map[&next_pos], 1)) .then(|| (node_map[pos], node_map[&next_pos], 1))
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()

View File

@@ -34,7 +34,7 @@ pub fn part1(input: &str) -> String {
.filter(|x| { .filter(|x| {
x.generate_adjacent() x.generate_adjacent()
.iter() .iter()
.any(|t| symbols.get(t).is_some()) .any(|t| symbols.contains_key(t))
}) })
.map(|x| x.no) .map(|x| x.no)
.sum::<u64>() .sum::<u64>()

View File

@@ -74,6 +74,7 @@ impl ItemMap {
.expect("always") .expect("always")
} }
} }
/// part1 of day 5 of AOC 2023 /// part1 of day 5 of AOC 2023
/// ///
/// # Arguments /// # Arguments
@@ -81,7 +82,6 @@ impl ItemMap {
/// ///
/// # Panics /// # Panics
/// panics whenever the input isn't parsable /// panics whenever the input isn't parsable
#[must_use] #[must_use]
pub fn part1(input: &str) -> String { pub fn part1(input: &str) -> String {
let (_input, (mut to_process, maps)) = parse_input(input).expect("aoc always has input"); let (_input, (mut to_process, maps)) = parse_input(input).expect("aoc always has input");

972
2024/Cargo.lock generated Normal file
View File

@@ -0,0 +1,972 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "addr2line"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1"
dependencies = [
"gimli",
]
[[package]]
name = "adler2"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "anyhow"
version = "1.0.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c95c10ba0b00a02636238b814946408b1322d5ac4760326e6fb8ec956d85775"
[[package]]
name = "autocfg"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "backtrace"
version = "0.3.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-targets",
]
[[package]]
name = "bitflags"
version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "day-1"
version = "2024.0.0"
dependencies = [
"dhat",
"error-stack",
"itertools",
"log",
"nom",
"test-log",
"thiserror",
]
[[package]]
name = "day-2"
version = "2024.0.0"
dependencies = [
"dhat",
"error-stack",
"itertools",
"log",
"nom",
"rstest",
"test-log",
"thiserror",
]
[[package]]
name = "day-3"
version = "2024.0.0"
dependencies = [
"dhat",
"error-stack",
"itertools",
"log",
"nom",
"regex",
"test-log",
"thiserror",
]
[[package]]
name = "dhat"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98cd11d84628e233de0ce467de10b8633f4ddaecafadefc86e13b84b8739b827"
dependencies = [
"backtrace",
"lazy_static",
"mintex",
"parking_lot",
"rustc-hash",
"serde",
"serde_json",
"thousands",
]
[[package]]
name = "either"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
[[package]]
name = "env_filter"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f2c92ceda6ceec50f43169f9ee8424fe2db276791afde7b2cd8bc084cb376ab"
dependencies = [
"log",
]
[[package]]
name = "env_logger"
version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13fa619b91fb2381732789fc5de83b45675e882f66623b7d8cb4f643017018d"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"log",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "error-stack"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe413319145d1063f080f27556fd30b1d70b01e2ba10c2a6e40d4be982ffc5d1"
dependencies = [
"anyhow",
"rustc_version",
]
[[package]]
name = "futures"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876"
dependencies = [
"futures-channel",
"futures-core",
"futures-executor",
"futures-io",
"futures-sink",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-channel"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10"
dependencies = [
"futures-core",
"futures-sink",
]
[[package]]
name = "futures-core"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
[[package]]
name = "futures-executor"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f"
dependencies = [
"futures-core",
"futures-task",
"futures-util",
]
[[package]]
name = "futures-io"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
[[package]]
name = "futures-macro"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "futures-sink"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7"
[[package]]
name = "futures-task"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988"
[[package]]
name = "futures-timer"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24"
[[package]]
name = "futures-util"
version = "0.3.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
dependencies = [
"futures-channel",
"futures-core",
"futures-io",
"futures-macro",
"futures-sink",
"futures-task",
"memchr",
"pin-project-lite",
"pin-utils",
"slab",
]
[[package]]
name = "gimli"
version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "hashbrown"
version = "0.15.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289"
[[package]]
name = "indexmap"
version = "2.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62f822373a4fe84d4bb149bf54e584a7f4abec90e072ed49cda0edea5b95471f"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itertools"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
dependencies = [
"either",
]
[[package]]
name = "itoa"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.166"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2ccc108bbc0b1331bd061864e7cd823c0cab660bbe6970e66e2c0614decde36"
[[package]]
name = "lock_api"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "matchers"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558"
dependencies = [
"regex-automata 0.1.10",
]
[[package]]
name = "memchr"
version = "2.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]]
name = "minimal-lexical"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1"
dependencies = [
"adler2",
]
[[package]]
name = "mintex"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bec4598fddb13cc7b528819e697852653252b760f1228b7642679bf2ff2cd07"
[[package]]
name = "nom"
version = "7.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
dependencies = [
"memchr",
"minimal-lexical",
]
[[package]]
name = "nu-ansi-term"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84"
dependencies = [
"overload",
"winapi",
]
[[package]]
name = "object"
version = "0.36.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.20.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
[[package]]
name = "overload"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
[[package]]
name = "parking_lot"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets",
]
[[package]]
name = "pin-project-lite"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff"
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "proc-macro-crate"
version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecf48c7ca261d60b74ab1a7b20da18bede46776b2e55535cb958eb595c5fa7b"
dependencies = [
"toml_edit",
]
[[package]]
name = "proc-macro2"
version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
dependencies = [
"proc-macro2",
]
[[package]]
name = "redox_syscall"
version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f"
dependencies = [
"bitflags",
]
[[package]]
name = "regex"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata 0.4.9",
"regex-syntax 0.8.5",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
dependencies = [
"regex-syntax 0.6.29",
]
[[package]]
name = "regex-automata"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax 0.8.5",
]
[[package]]
name = "regex-syntax"
version = "0.6.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1"
[[package]]
name = "regex-syntax"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "relative-path"
version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba39f3699c378cd8970968dcbff9c43159ea4cfbd88d43c00b22f2ef10a435d2"
[[package]]
name = "rstest"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a2c585be59b6b5dd66a9d2084aa1d8bd52fbdb806eafdeffb52791147862035"
dependencies = [
"futures",
"futures-timer",
"rstest_macros",
"rustc_version",
]
[[package]]
name = "rstest_macros"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "825ea780781b15345a146be27eaefb05085e337e869bff01b4306a4fd4a9ad5a"
dependencies = [
"cfg-if",
"glob",
"proc-macro-crate",
"proc-macro2",
"quote",
"regex",
"relative-path",
"rustc_version",
"syn",
"unicode-ident",
]
[[package]]
name = "rustc-demangle"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc_version"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
dependencies = [
"semver",
]
[[package]]
name = "ryu"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "semver"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b"
[[package]]
name = "serde"
version = "1.0.215"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.215"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.133"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377"
dependencies = [
"itoa",
"memchr",
"ryu",
"serde",
]
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]]
name = "slab"
version = "0.4.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
dependencies = [
"autocfg",
]
[[package]]
name = "smallvec"
version = "1.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
[[package]]
name = "syn"
version = "2.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44d46482f1c1c87acd84dea20c1bf5ebff4c757009ed6bf19cfd36fb10e92c4e"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "test-log"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3dffced63c2b5c7be278154d76b479f9f9920ed34e7574201407f0b14e2bbb93"
dependencies = [
"env_logger",
"test-log-macros",
"tracing-subscriber",
]
[[package]]
name = "test-log-macros"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5999e24eaa32083191ba4e425deb75cdf25efefabe5aaccb7446dd0d4122a3f5"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "thiserror"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "thousands"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bf63baf9f5039dadc247375c29eb13706706cfde997d0330d05aa63a77d8820"
[[package]]
name = "thread_local"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "toml_datetime"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
[[package]]
name = "toml_edit"
version = "0.22.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5"
dependencies = [
"indexmap",
"toml_datetime",
"winnow",
]
[[package]]
name = "tracing"
version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-log"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3"
dependencies = [
"log",
"once_cell",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
"matchers",
"nu-ansi-term",
"once_cell",
"regex",
"sharded-slab",
"thread_local",
"tracing",
"tracing-core",
"tracing-log",
]
[[package]]
name = "unicode-ident"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_gnullvm",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winnow"
version = "0.6.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b"
dependencies = [
"memchr",
]

View File

@@ -26,7 +26,7 @@ rustworkx-core = "0.15.1"
pathfinding = "4.11.0" pathfinding = "4.11.0"
test-log = {version="0.2.16", features=["default", "unstable"]} test-log = {version="0.2.16", features=["default", "unstable"]}
thiserror = "2.0.3" thiserror = "2.0.3"
regex = "1.11.1"
[profile.dhat] [profile.dhat]
inherits = "release" inherits = "release"

View File

@@ -41,8 +41,8 @@ pub enum Day2Part1Error {
ParseError, ParseError,
} }
/// Day-2 Part 1 for 2024 advent of code /// Day-3 Part 1 for 2024 advent of code
/// Problem can be found here: <https://adventofcode.com/2024/day/2> /// Problem can be found here: <https://adventofcode.com/2024/day/3>
/// ///
/// # Errors /// # Errors
/// - `ParseError` there was an issue with the parser /// - `ParseError` there was an issue with the parser

View File

@@ -15,6 +15,7 @@ log.workspace = true
error-stack.workspace = true error-stack.workspace = true
thiserror.workspace = true thiserror.workspace = true
dhat.workspace = true dhat.workspace = true
regex.workspace = true
[dev-dependencies] [dev-dependencies]
test-log.workspace = true test-log.workspace = true

View File

@@ -1,30 +1,43 @@
#![warn(clippy::all, clippy::pedantic)] #![warn(clippy::all, clippy::pedantic)]
use error_stack::Result; use error_stack::{Report, Result, ResultExt};
use regex::Regex;
use thiserror::Error; use thiserror::Error;
// day-3 // day-3
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum Day3Part1Error{ pub enum Day3Part1Error {
#[error("Problem parsing Day 3")] #[error("Problem parsing Day 3")]
ParseError, ParseError,
} }
pub fn part1 (_input: &str) -> Result<String, Day3Part1Error> { /// Day-2 Part 1 for 2024 advent of code
Ok("Not Finished".to_string()) /// Problem can be found here: <https://adventofcode.com/2024/day/2>
///
/// # Errors
/// - `ParseError` there was an issue with the parser
pub fn part1(input: &str) -> Result<String, Day3Part1Error> {
let re = Regex::new(r"mul\((\d{1,3}),(\d{1,3})\)")
.map_err( Report::from)
.change_context(Day3Part1Error::ParseError)?;
Ok(re
.captures_iter(input)
.map(|x| x[1].parse::<i64>().unwrap_or(0) * x[2].parse::<i64>().unwrap_or(0))
.sum::<i64>()
.to_string())
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
const INPUT: &str = ""; const INPUT: &str = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))";
#[test_log::test] #[test_log::test]
#[test_log(default_log_filter = "trace")] #[test_log(default_log_filter = "trace")]
fn part1_works() { fn part1_works() {
let result = part1(INPUT).unwrap(); let result = part1(INPUT).unwrap();
assert_eq!(result, "Not Finished".to_string()); assert_eq!(result, "161".to_string());
} }
} }

View File

@@ -1,30 +1,94 @@
#![warn(clippy::all, clippy::pedantic)] #![warn(clippy::all, clippy::pedantic)]
use error_stack::Result; use error_stack::{Report, Result, ResultExt};
use regex::Regex;
use thiserror::Error; use thiserror::Error;
// day-3 // day-3
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum Day3Part2Error{ pub enum Day3Part2Error {
#[error("Problem parsing Day 3")] #[error("Problem parsing Day 3")]
ParseError, ParseError,
} }
pub fn part2 (_input: &str) -> Result<String, Day3Part2Error> { /// Day-3 Part 2 for 2024 advent of code
Ok("Not Finished".to_string()) /// Problem can be found here: <https://adventofcode.com/2024/day/3#part2>
///
/// # Errors
/// - `ParseError` there was an issue with the parser
pub fn part2(input: &str) -> Result<String, Day3Part2Error> {
let do_re = Regex::new(r"do\(\)")
.map_err( Report::from)
.change_context(Day3Part2Error::ParseError)?;
let dos = do_re
.find_iter(input)
.map(|x| (x.start(), x.end()))
.collect::<Vec<_>>();
let dont_re = Regex::new(r"don't\(\)")
.map_err( Report::from)
.change_context(Day3Part2Error::ParseError)?;
let donts = dont_re
.find_iter(input)
.map(|x| (x.start(), x.end()))
.collect::<Vec<_>>();
let mut dos_index = 0;
let mut donts_index = 0;
let mut white_list = true;
let mut blackout_ranges = Vec::new();
let mut blacklist_start = 0;
while dos_index < dos.len() && donts_index < donts.len() {
if white_list {
if dos[dos_index].1 < donts[donts_index].0 {
//currently whitelisted so dos are no-ops
dos_index += 1;
} else {
blacklist_start = donts[donts_index].0;
white_list = false;
}
} else if donts[donts_index].1 < dos[dos_index].0 {
//in a black list so donts are no-ops
donts_index += 1;
} else {
blackout_ranges.push(blacklist_start..dos[dos_index].1);
blacklist_start = 0;
white_list = true;
}
}
if donts_index < donts.len() {
blackout_ranges.push(donts[donts_index].0..input.len());
} else if dos_index < dos.len() && blacklist_start != 0 {
blackout_ranges.push(blacklist_start..dos[dos_index].1);
}
let re = Regex::new(r"mul\((\d{1,3}),(\d{1,3})\)")
.map_err( Report::from)
.change_context(Day3Part2Error::ParseError)?;
let mut sum = 0;
for mult_match in re.find_iter(input) {
if blackout_ranges
.iter()
.any(|x| x.contains(&mult_match.start()))
{
continue;
}
let values = re.captures(mult_match.as_str())
.ok_or(Report::new( Day3Part2Error::ParseError))?;
sum += values[1].parse::<i64>().unwrap_or(0) * values[2].parse::<i64>().unwrap_or(0);
}
Ok(sum.to_string())
} }
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use super::*; use super::*;
const INPUT: &str = ""; const INPUT: &str = "xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))";
#[test_log::test] #[test_log::test]
#[test_log(default_log_filter = "trace")] #[test_log(default_log_filter = "trace")]
fn part2_works() { fn part2_works() {
let result = part2(INPUT).unwrap(); let result = part2(INPUT).unwrap();
assert_eq!(result, "Not Finished".to_string()); assert_eq!(result, "48".to_string());
} }
} }

24
2024/day-4/Cargo.toml Normal file
View File

@@ -0,0 +1,24 @@
[package]
name = "day-4"
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]
nom.workspace = true
itertools.workspace = true
log.workspace = true
error-stack.workspace = true
thiserror.workspace = true
dhat.workspace = true
glam.workspace = true
[dev-dependencies]
test-log.workspace = true
[features]
dhat-heap = []

4
2024/day-4/src/lib.rs Normal file
View File

@@ -0,0 +1,4 @@
pub mod part1;
pub use crate::part1::*;
pub mod part2;
pub use crate::part2::*;

31
2024/day-4/src/main.rs Normal file
View File

@@ -0,0 +1,31 @@
#![warn(clippy::all, clippy::pedantic)]
use day_4::part1;
use day_4::part2;
use error_stack::{Result, ResultExt};
use thiserror::Error;
#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
#[derive(Debug, Error)]
enum Day4Error {
#[error("Part 1 failed")]
Part1Error,
#[error("Part 2 failed")]
Part2Error,
}
fn main() -> Result<(), Day4Error> {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();
let input = include_str!("./input.txt");
let part1_result = part1(input).change_context(Day4Error::Part1Error)?;
println!("part 1: {part1_result}");
let part2_result = part2(input).change_context(Day4Error::Part2Error)?;
println!("part 2: {part2_result}");
Ok(())
}

111
2024/day-4/src/part1.rs Normal file
View File

@@ -0,0 +1,111 @@
#![warn(clippy::all, clippy::pedantic)]
use error_stack::Result;
use glam::IVec2;
use thiserror::Error;
// day-4
#[derive(Debug, Error)]
pub enum Day4Part1Error {
#[error("Problem parsing Day 4")]
ParseError,
}
#[allow(clippy::cast_sign_loss)]
/// Day-4 Part 1 for 2024 advent of code
/// Problem can be found here: <https://adventofcode.com/2024/day/4>
///
/// # Errors
/// - `ParseError` there was an issue with the parser
///
/// # Panics
/// - If there is a catastropic error as it only panics in event that a lenght is negative
pub fn part1(input: &str) -> Result<String, Day4Part1Error> {
//read in grid
let grid = input
.lines()
.map(|line| Vec::from(line.as_bytes()))
.collect::<Vec<_>>();
let num_of_rows = grid
.len()
.try_into()
.expect("length cannot be negative ever");
let num_of_cols = grid[0].len().try_into().unwrap(); //because we know it will be rectangular
//window over each letter (skip over not x's
let total: usize = grid
.iter()
.enumerate()
.map(|(row_num, row)| {
row.iter()
.enumerate()
.map(|(col_num, col)| {
if *col == b'X' {
//window over the rest
let point =
IVec2::new(row_num.try_into().unwrap(), col_num.try_into().unwrap());
[
IVec2::NEG_X,
IVec2::NEG_ONE,
IVec2::NEG_Y,
IVec2::new(1, -1),
IVec2::X,
IVec2::ONE,
IVec2::Y,
IVec2::new(-1, 1),
]
.iter()
.filter(|dir| {
let extent = point + (*dir * 3);
if extent.x < 0
|| extent.x >= num_of_rows
|| extent.y < 0
|| extent.y >= num_of_cols
{
return false;
}
let m = point + *dir;
let a = point + 2 * *dir;
let s = point + 3 * *dir;
grid.get(m.x as u32 as usize)
.map(|g| g.get(m.y as u32 as usize))
.unwrap();
grid[m.x as u32 as usize][m.y as u32 as usize] == b'M'
&& grid[a.x as u32 as usize][a.y as u32 as usize] == b'A'
&& grid[s.x as u32 as usize][s.y as u32 as usize] == b'S'
})
.count()
//todo!("at pos {row_num} - {col_num}")
} else {
0_usize
}
})
.sum::<usize>()
})
.sum();
//count
Ok(total.to_string())
}
#[cfg(test)]
mod test {
use super::*;
const INPUT: &str = "MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX";
#[test_log::test]
#[test_log(default_log_filter = "trace")]
fn part1_works() {
let result = part1(INPUT).unwrap();
assert_eq!(result, "18".to_string());
}
}

102
2024/day-4/src/part2.rs Normal file
View File

@@ -0,0 +1,102 @@
#![warn(clippy::all, clippy::pedantic)]
use error_stack::Result;
use glam::IVec2;
use thiserror::Error;
// day-4
#[derive(Debug, Error)]
pub enum Day4Part2Error {
#[error("Problem parsing Day 4")]
ParseError,
}
/// Day-4 Part 2 for 2024 advent of code
/// Problem can be found here: <https://adventofcode.com/2024/day/4#part2>
///
/// # Errors
/// - `ParseError` there was an issue with the parser
///
/// # Panics
/// - If there is a catastropic error as it only panics in event that a lenght is negative
pub fn part2(input: &str) -> Result<String, Day4Part2Error> {
//read in grid
let grid = input
.lines()
.map(|line| Vec::from(line.as_bytes()))
.collect::<Vec<_>>();
let num_of_rows = grid.len();
let num_of_cols = grid[0].len();
//window over each letter (skip over not x's
let total: usize = grid
.iter()
.enumerate()
.skip(1)
.take(num_of_rows - 2)
.map(|(row_num, row)| {
row.iter()
.enumerate()
.skip(1)
.take(num_of_cols - 2)
.map(|(col_num, col)| {
if *col == b'A' {
//window over the rest
let point =
IVec2::new(row_num.try_into().unwrap(), col_num.try_into().unwrap());
let up_forward = point + IVec2::new(-1, 1);
let up_back = point + IVec2::NEG_ONE;
let down_forward = point + IVec2::ONE;
let down_back = point + IVec2::new(1, -1);
#[allow(clippy::cast_sign_loss)]
(((grid[up_back.x as u32 as usize][up_back.y as u32 as usize] == b'M'
&& grid[down_forward.x as u32 as usize]
[down_forward.y as u32 as usize]
== b'S')
|| (grid[up_back.x as u32 as usize][up_back.y as u32 as usize] == b'S'
&& grid[down_forward.x as u32 as usize]
[down_forward.y as u32 as usize]
== b'M'))
&& ((grid[down_back.x as u32 as usize][down_back.y as u32 as usize]
== b'M'
&& grid[up_forward.x as u32 as usize]
[up_forward.y as u32 as usize]
== b'S')
|| (grid[down_back.x as u32 as usize][down_back.y as u32 as usize]
== b'S'
&& grid[up_forward.x as u32 as usize]
[up_forward.y as u32 as usize]
== b'M'))).into()
} else {
0_usize
}
})
.sum::<usize>()
})
.sum();
//count
Ok(total.to_string())
}
#[cfg(test)]
mod test {
use super::*;
const INPUT: &str = "MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX";
#[test_log::test]
#[test_log(default_log_filter = "trace")]
fn part2_works() {
let result = part2(INPUT).unwrap();
assert_eq!(result, "9".to_string());
}
}

23
2024/day-5/Cargo.toml Normal file
View File

@@ -0,0 +1,23 @@
[package]
name = "day-5"
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]
nom.workspace = true
itertools.workspace = true
log.workspace = true
error-stack.workspace = true
thiserror.workspace = true
dhat.workspace = true
[dev-dependencies]
test-log.workspace = true
[features]
dhat-heap = []

4
2024/day-5/src/lib.rs Normal file
View File

@@ -0,0 +1,4 @@
pub mod part1;
pub use crate::part1::*;
pub mod part2;
pub use crate::part2::*;

31
2024/day-5/src/main.rs Normal file
View File

@@ -0,0 +1,31 @@
#![warn(clippy::all, clippy::pedantic)]
use day_5::part1;
use day_5::part2;
use error_stack::{Result, ResultExt};
use thiserror::Error;
#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
#[derive(Debug, Error)]
enum Day5Error {
#[error("Part 1 failed")]
Part1Error,
#[error("Part 2 failed")]
Part2Error,
}
fn main() -> Result<(), Day5Error> {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();
let input = include_str!("./input.txt");
let part1_result = part1(input).change_context(Day5Error::Part1Error)?;
println!("part 1: {part1_result}");
let part2_result = part2(input).change_context(Day5Error::Part2Error)?;
println!("part 2: {part2_result}");
Ok(())
}

119
2024/day-5/src/part1.rs Normal file
View File

@@ -0,0 +1,119 @@
#![warn(clippy::all, clippy::pedantic)]
use std::collections::HashMap;
use error_stack::{Report, Result, ResultExt};
use nom::{
bytes::complete::tag, character::complete, multi::separated_list1, sequence::separated_pair,
IResult,
};
use thiserror::Error;
// day-5
#[derive(Debug, Error)]
pub enum Day5Part1Error {
#[error("Problem parsing Day 5")]
ParseError,
}
type Orderings = HashMap<u32, Vec<u32>>;
/// Day-5 Part 1 for 2024 advent of code
/// Problem can be found here: <https://adventofcode.com/2024/day/5>
///
/// # Errors
/// - `ParseError` there was an issue with the parser
pub fn part1(input: &str) -> Result<String, Day5Part1Error> {
//parse into "bad list where X|Y
let (_, (ordering, updates)) = parse_input(input)
.map_err(|x| Report::from(x.to_owned()))
.change_context(Day5Part1Error::ParseError)?;
let middles: u32 = updates
.iter()
.filter_map(|update| {
let update_len = update.len();
for i in 0..update_len {
let before = &update[..i];
if let Some(a) = update.get(i) {
if let Some(rules) = ordering.get(a) {
if rules.iter().any(|b| before.contains(b)) {
return None;
}
}
}
}
Some(update[update_len / 2])
})
.sum();
Ok(middles.to_string())
}
fn parse_ordering(input: &str) -> IResult<&str, Orderings> {
let (input, rules) = separated_list1(
complete::line_ending,
separated_pair(complete::u32, tag("|"), complete::u32),
)(input)?;
let ordering = rules.iter().fold(HashMap::new(), |mut acc: Orderings, (a, b)| {
acc.entry(*a).or_default().push(*b);
acc
});
Ok((input, ordering))
}
fn parse_update(input: &str) -> IResult<&str, Vec<u32>> {
separated_list1(tag(","), complete::u32)(input)
}
fn parse_updates(input: &str) -> IResult<&str, Vec<Vec<u32>>> {
separated_list1(complete::line_ending, parse_update)(input)
}
fn parse_input(input: &str) -> IResult<&str, (Orderings, Vec<Vec<u32>>)> {
let (input, ordering) = parse_ordering(input)?;
let (input, _) = complete::line_ending(input)?;
let (input, _) = complete::line_ending(input)?;
let (input, updates) = parse_updates(input)?;
Ok((input, (ordering, updates)))
}
#[cfg(test)]
mod test {
use super::*;
const INPUT: &str = "47|53
97|13
97|61
97|47
75|29
61|13
75|53
29|13
97|29
53|29
61|53
97|53
61|29
47|13
75|47
97|75
47|61
75|61
47|29
75|13
53|13
75,47,61,53,29
97,61,53,29,13
75,29,13
75,97,47,61,53
61,13,29
97,13,75,29,47";
#[test_log::test]
#[test_log(default_log_filter = "trace")]
fn part1_works() {
let result = part1(INPUT).unwrap();
assert_eq!(result, "143".to_string());
}
}

127
2024/day-5/src/part2.rs Normal file
View File

@@ -0,0 +1,127 @@
#![warn(clippy::all, clippy::pedantic)]
use std::{cmp::Ordering, collections::HashMap};
use error_stack::{Report, Result, ResultExt};
use nom::{bytes::complete::tag, character::complete, multi::separated_list1, sequence::separated_pair, IResult};
use thiserror::Error;
// day-5
#[derive(Debug, Error)]
pub enum Day5Part2Error{
#[error("Problem parsing Day 5")]
ParseError,
}
type Orderings = HashMap<u32, Vec<u32>>;
/// Day-5 Part 2 for 2024 advent of code
/// Problem can be found here: <https://adventofcode.com/2024/day/5#part2>
///
/// # Errors
/// - `ParseError` there was an issue with the parser
pub fn part2 (input: &str) -> Result<String, Day5Part2Error> {
let (_, (ordering, mut updates)) = parse_input(input)
.map_err(|x| Report::from(x.to_owned()))
.change_context(Day5Part2Error::ParseError)?;
let middles: u32 = updates
.iter_mut()
.filter_map(|update| {
let update_len = update.len();
for i in 0..update_len {
let before = &update[..i];
if let Some(a) = update.get(i) {
if let Some(rules) = ordering.get(a) {
if rules.iter().any(|b| before.contains(b)) {
return Some(update);
}
}
}
}
None
})
.map(|update| {
update.sort_by(|a,b| {
let Some(rule_a) = ordering.get(a) else { return Ordering::Equal;} ;
//let Some(rule_b) = ordering.get(b) else { return Ordering::Equal;} ;
if rule_a.contains(b) {
return Ordering::Less;
}
Ordering::Equal
});
update[update.len()/2]
})
.sum();
Ok(middles.to_string())
}
fn parse_ordering(input: &str) -> IResult<&str, Orderings> {
let (input, rules) = separated_list1(
complete::line_ending,
separated_pair(complete::u32, tag("|"), complete::u32),
)(input)?;
let ordering = rules.iter().fold(HashMap::new(), |mut acc: Orderings, (a, b)| {
acc.entry(*a).or_default().push(*b);
acc
});
Ok((input, ordering))
}
fn parse_update(input: &str) -> IResult<&str, Vec<u32>> {
separated_list1(tag(","), complete::u32)(input)
}
fn parse_updates(input: &str) -> IResult<&str, Vec<Vec<u32>>> {
separated_list1(complete::line_ending, parse_update)(input)
}
fn parse_input(input: &str) -> IResult<&str, (Orderings, Vec<Vec<u32>>)> {
let (input, ordering) = parse_ordering(input)?;
let (input, _) = complete::line_ending(input)?;
let (input, _) = complete::line_ending(input)?;
let (input, updates) = parse_updates(input)?;
Ok((input, (ordering, updates)))
}
#[cfg(test)]
mod test {
use super::*;
const INPUT: &str = "47|53
97|13
97|61
97|47
75|29
61|13
75|53
29|13
97|29
53|29
61|53
97|53
61|29
47|13
75|47
97|75
47|61
75|61
47|29
75|13
53|13
75,47,61,53,29
97,61,53,29,13
75,29,13
75,97,47,61,53
61,13,29
97,13,75,29,47";
#[test_log::test]
#[test_log(default_log_filter = "trace")]
fn part2_works() {
let result = part2(INPUT).unwrap();
assert_eq!(result, "123".to_string());
}
}

24
2024/day-6/Cargo.toml Normal file
View File

@@ -0,0 +1,24 @@
[package]
name = "day-6"
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]
nom.workspace = true
itertools.workspace = true
log.workspace = true
error-stack.workspace = true
thiserror.workspace = true
dhat.workspace = true
glam.workspace =true
[dev-dependencies]
test-log.workspace = true
[features]
dhat-heap = []

4
2024/day-6/src/lib.rs Normal file
View File

@@ -0,0 +1,4 @@
pub mod part1;
pub use crate::part1::*;
pub mod part2;
pub use crate::part2::*;

31
2024/day-6/src/main.rs Normal file
View File

@@ -0,0 +1,31 @@
#![warn(clippy::all, clippy::pedantic)]
use day_6::part1;
use day_6::part2;
use error_stack::{Result, ResultExt};
use thiserror::Error;
#[cfg(feature = "dhat-heap")]
#[global_allocator]
static ALLOC: dhat::Alloc = dhat::Alloc;
#[derive(Debug, Error)]
enum Day6Error {
#[error("Part 1 failed")]
Part1Error,
#[error("Part 2 failed")]
Part2Error,
}
fn main() -> Result<(), Day6Error> {
#[cfg(feature = "dhat-heap")]
let _profiler = dhat::Profiler::new_heap();
let input = include_str!("./input.txt");
let part1_result = part1(input).change_context(Day6Error::Part1Error)?;
println!("part 1: {part1_result}");
let part2_result = part2(input).change_context(Day6Error::Part2Error)?;
println!("part 2: {part2_result}");
Ok(())
}

247
2024/day-6/src/part1.rs Normal file
View File

@@ -0,0 +1,247 @@
#![warn(clippy::all, clippy::pedantic)]
use std::{collections::HashSet, ops::Sub};
use glam::IVec2;
use thiserror::Error;
// day-6
#[derive(Debug, Error)]
pub enum Day6Part1Error {
#[error("Problem parsing Day 6")]
ParseError,
}
#[derive(Debug)]
enum Direction {
North,
East,
South,
West,
}
impl From<&Direction> for IVec2 {
fn from(value: &Direction) -> Self {
match value {
Direction::North => IVec2::NEG_X,
Direction::East => IVec2::Y,
Direction::South => IVec2::X,
Direction::West => IVec2::NEG_Y,
}
}
}
impl Sub<&Direction> for &IVec2 {
type Output = IVec2;
fn sub(self, rhs: &Direction) -> Self::Output {
self - (match rhs {
Direction::North => IVec2::NEG_X,
Direction::East => IVec2::Y,
Direction::South => IVec2::X,
Direction::West => IVec2::NEG_Y,
})
}
}
impl Direction {
pub fn next(&self) -> Self {
match self {
Direction::North => Direction::East,
Direction::East => Direction::South,
Direction::South => Direction::West,
Direction::West => Direction::North,
}
}
}
#[derive(Debug)]
struct MyMap {
pub obstacles: HashSet<IVec2>,
pub height: u32,
pub width: u32,
}
impl MyMap {
pub fn next_obstacle(&self, start_pos: &IVec2, direction: &Direction) -> Option<&IVec2> {
self.obstacles
.iter()
.filter(|obstacle| match direction {
Direction::North => obstacle.y == start_pos.y && obstacle.x < start_pos.x,
Direction::East => obstacle.x == start_pos.x && obstacle.y > start_pos.y,
Direction::South => obstacle.y == start_pos.y && obstacle.x > start_pos.x,
Direction::West => obstacle.x == start_pos.x && obstacle.y < start_pos.y,
})
.fold(None, |acc, obstacle| match direction {
Direction::North if acc == None || obstacle.x > acc.unwrap().x => Some(obstacle),
Direction::East if acc == None || obstacle.y < acc.unwrap().y => Some(obstacle),
Direction::South if acc == None || obstacle.x < acc.unwrap().x => Some(obstacle),
Direction::West if acc == None || obstacle.y > acc.unwrap().y => Some(obstacle),
_ => acc,
})
}
}
/// Day-6 Part 2 for 2024 advent of code
/// Problem can be found here: <https://adventofcode.com/2024/day/6>
///
/// # Errors
/// - `ParseError` there was an issue with the parser
pub fn part1(input: &str) -> Result<String, Day6Part1Error> {
//let input = Span::new(input);
//TODO figure out how to real error
let (mut guard_pos, map) = parse_input(input);
let mut guard_dir = Direction::North;
let mut visited = HashSet::new();
while guard_pos.x >= 0
&& guard_pos.y >= 0
&& (guard_pos.x as u32) < map.height
&& (guard_pos.y as u32) < map.width
{
let _ = visited.insert(guard_pos);
if let Some(next_obstacle) = map.next_obstacle(&guard_pos, &guard_dir) {
// println!("Hit row {}, col {} going {:?}", next_obstacle.x, next_obstacle.y, guard_dir);
match guard_dir {
Direction::North => {
((next_obstacle.x+1)..guard_pos.x)
.map(|x| IVec2::new(x, guard_pos.y))
.for_each(|x| {
visited.insert(x);
});
},
Direction::South => {
(guard_pos.x..(next_obstacle.x-1))
.map(|x| IVec2::new(x, guard_pos.y))
.for_each(|x| {
visited.insert(x);
});
},
Direction::East => {
(guard_pos.y..(next_obstacle.y-1))
.map(|y| IVec2::new(guard_pos.x, y))
.for_each(|x| {
visited.insert(x);
});
},
Direction::West => {
((next_obstacle.y+1)..guard_pos.y)
.map(|y| IVec2::new(guard_pos.x, y))
.for_each(|x| {
visited.insert(x);
});
},
};
guard_pos = next_obstacle - &guard_dir;
} else {
let new_pos = match guard_dir {
Direction::North => IVec2::new(-1, guard_pos.y),
Direction::East => IVec2::new(guard_pos.x, map.width.try_into().unwrap()),
Direction::South => IVec2::new(map.height.try_into().unwrap(), guard_pos.y),
Direction::West => IVec2::new(guard_pos.x, -1),
};
// println!("Left map at row {}, col {}", new_pos.x, new_pos.y);
match guard_dir {
Direction::North => {
((new_pos.x+1)..guard_pos.x)
.map(|x| IVec2::new(x, guard_pos.y))
.for_each(|x| {
visited.insert(x);
});
}
Direction::South => {
(guard_pos.x..new_pos.x)
.map(|x| IVec2::new(x, guard_pos.y))
.for_each(|x| {
visited.insert(x);
});
}
Direction::East => {
(guard_pos.y..new_pos.y)
.map(|y| IVec2::new(guard_pos.x, y))
.for_each(|x| {
visited.insert(x);
});
}
Direction::West => {
((new_pos.y+1)..guard_pos.y)
.map(|y| IVec2::new(guard_pos.x, y))
.for_each(|x| {
visited.insert(x);
});
}
};
guard_pos = new_pos;
//break
}
guard_dir = guard_dir.next();
/*
for row in 0.. map.height.try_into().unwrap() {
for col in 0..map.width.try_into().unwrap() {
let pos = IVec2::new(row, col);
if visited.contains(&pos) {
print!("X");
} else {
print!(".");
}
}
print!("\n");
}*/
}
Ok(visited.iter().count().to_string())
}
fn parse_input(input: &str) -> (IVec2, MyMap) {
let (pos, height, width, obstacles) = input.lines().into_iter().enumerate().fold(
(IVec2::ZERO, 0, 0, HashSet::new()),
|mut acc, (row_no, row)| {
acc.1 = row_no.try_into().unwrap();
acc.2 = row.len().try_into().unwrap();
row.chars()
.enumerate()
.filter(|(_, c)| *c == '#' || *c == '^')
.for_each(|(col_no, c)| {
if c == '#' {
acc.3.insert(IVec2::new(
row_no.try_into().unwrap(),
col_no.try_into().unwrap(),
));
} else {
acc.0 = IVec2::new(row_no.try_into().unwrap(), col_no.try_into().unwrap());
}
});
acc
},
);
(
pos,
MyMap {
obstacles,
height: height + 1,
width,
},
)
}
#[cfg(test)]
mod test {
use super::*;
const INPUT: &str = "....#.....
.........#
..........
..#.......
.......#..
..........
.#..^.....
........#.
#.........
......#...";
#[test_log::test]
#[test_log(default_log_filter = "trace")]
fn part1_works() {
let result = part1(INPUT).unwrap();
assert_eq!(result, "41".to_string());
}
}

35
2024/day-6/src/part2.rs Normal file
View File

@@ -0,0 +1,35 @@
#![warn(clippy::all, clippy::pedantic)]
use error_stack::Result;
use thiserror::Error;
// day-6
#[derive(Debug, Error)]
pub enum Day6Part2Error{
#[error("Problem parsing Day 6")]
ParseError,
}
/// Day-6 Part 2 for 2024 advent of code
/// Problem can be found here: <https://adventofcode.com/2024/day/6#part2>
///
/// # Errors
/// - `ParseError` there was an issue with the parser
pub fn part2 (_input: &str) -> Result<String, Day6Part2Error> {
Ok("Not Finished".to_string())
}
#[cfg(test)]
mod test {
use super::*;
const INPUT: &str = "";
#[test_log::test]
#[test_log(default_log_filter = "trace")]
fn part2_works() {
let result = part2(INPUT).unwrap();
assert_eq!(result, "Not Finished".to_string());
}
}