why where these changed no one knows but past me
This commit is contained in:
2
2023/Cargo.lock
generated
2
2023/Cargo.lock
generated
@@ -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",
|
||||||
|
|||||||
@@ -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"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 = []
|
||||||
|
|||||||
@@ -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}");
|
||||||
|
|||||||
@@ -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 = []
|
||||||
|
|||||||
@@ -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}");
|
||||||
|
|||||||
Reference in New Issue
Block a user