why where these changed no one knows but past me

This commit is contained in:
Dylan Thies
2024-12-02 11:29:22 -05:00
parent 0ceb59d424
commit 0e93372b96
7 changed files with 49 additions and 25 deletions

2
2023/Cargo.lock generated
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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