diff --git a/2022/rust/inputs/day19.txt b/2022/rust/inputs/day19.txt new file mode 100644 index 0000000..494d155 --- /dev/null +++ b/2022/rust/inputs/day19.txt @@ -0,0 +1,30 @@ +Blueprint 1: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 20 clay. Each geode robot costs 3 ore and 14 obsidian. +Blueprint 2: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 20 clay. Each geode robot costs 2 ore and 20 obsidian. +Blueprint 3: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 16 clay. Each geode robot costs 3 ore and 9 obsidian. +Blueprint 4: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 15 clay. Each geode robot costs 2 ore and 13 obsidian. +Blueprint 5: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 16 clay. Each geode robot costs 3 ore and 13 obsidian. +Blueprint 6: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 14 clay. Each geode robot costs 3 ore and 14 obsidian. +Blueprint 7: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 6 clay. Each geode robot costs 2 ore and 20 obsidian. +Blueprint 8: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 5 clay. Each geode robot costs 4 ore and 8 obsidian. +Blueprint 9: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 19 clay. Each geode robot costs 3 ore and 8 obsidian. +Blueprint 10: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 14 clay. Each geode robot costs 3 ore and 8 obsidian. +Blueprint 11: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 19 clay. Each geode robot costs 4 ore and 13 obsidian. +Blueprint 12: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 20 clay. Each geode robot costs 4 ore and 18 obsidian. +Blueprint 13: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 16 clay. Each geode robot costs 4 ore and 16 obsidian. +Blueprint 14: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 20 clay. Each geode robot costs 2 ore and 16 obsidian. +Blueprint 15: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 11 clay. Each geode robot costs 3 ore and 8 obsidian. +Blueprint 16: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 19 clay. Each geode robot costs 4 ore and 12 obsidian. +Blueprint 17: Each ore robot costs 2 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 20 clay. Each geode robot costs 3 ore and 15 obsidian. +Blueprint 18: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 15 clay. Each geode robot costs 4 ore and 20 obsidian. +Blueprint 19: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 4 ore and 15 clay. Each geode robot costs 4 ore and 9 obsidian. +Blueprint 20: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 2 ore and 7 clay. Each geode robot costs 2 ore and 9 obsidian. +Blueprint 21: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 3 ore and 19 obsidian. +Blueprint 22: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 17 clay. Each geode robot costs 3 ore and 13 obsidian. +Blueprint 23: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 18 clay. Each geode robot costs 4 ore and 19 obsidian. +Blueprint 24: Each ore robot costs 3 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 17 clay. Each geode robot costs 2 ore and 13 obsidian. +Blueprint 25: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 15 clay. Each geode robot costs 3 ore and 16 obsidian. +Blueprint 26: Each ore robot costs 4 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 15 clay. Each geode robot costs 2 ore and 13 obsidian. +Blueprint 27: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 18 clay. Each geode robot costs 4 ore and 9 obsidian. +Blueprint 28: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 7 clay. Each geode robot costs 2 ore and 19 obsidian. +Blueprint 29: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 15 clay. Each geode robot costs 4 ore and 17 obsidian. +Blueprint 30: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 4 ore and 9 clay. Each geode robot costs 4 ore and 16 obsidian. diff --git a/2022/rust/src/main.rs b/2022/rust/src/main.rs index 2401b2b..90fc2ee 100644 --- a/2022/rust/src/main.rs +++ b/2022/rust/src/main.rs @@ -20,5 +20,6 @@ fn main() { // solutions::day15::run(); // solutions::day16::run(); // solutions::day17::run(); - solutions::day18::run(); + // solutions::day18::run(); + solutions::day19::run(); } diff --git a/2022/rust/src/solutions/day19.rs b/2022/rust/src/solutions/day19.rs new file mode 100644 index 0000000..d7fa58a --- /dev/null +++ b/2022/rust/src/solutions/day19.rs @@ -0,0 +1,77 @@ +use regex::{CaptureMatches, Captures, Regex, SubCaptureMatches}; +use crate::utils; + + +pub fn run() -> () { + let data = parse_data(&utils::read_lines(utils::Source::Day(-1))); + + println!("Day X"); + println!("Part 1: {}", solve1(&data)); + println!("Part 2: {}", solve2(&data)); +} + +#[derive(Debug)] struct Ore(i32); +#[derive(Debug)] struct Clay(i32); +#[derive(Debug)] struct Obsidian(i32); + +#[derive(Debug)] +struct Blueprint { + id: usize, + ore: Ore, + clay: Ore, + obsidian: (Ore, Clay), + geode: (Ore, Obsidian), +} + + +fn solve1(data: &[Blueprint]) -> i32 { + println!("{:?}", data); + 1 +} + +fn solve2(data: &[Blueprint]) -> i32 { + 2 +} + +fn extract(cap: &Captures, at: usize) -> i32 { + cap.get(at).unwrap().as_str().parse().unwrap() +} + +fn parse_data>(data: &[T]) -> Vec { + let re = Regex::new( + r#"Blueprint (\d+): Each ore robot costs (\d+) ore\. Each clay robot costs (\d+) ore\. Each obsidian robot costs (\d+) ore and (\d+) clay\. Each geode robot costs (\d+) ore and (\d+) obsidian\."# + ).unwrap(); + data.iter() + .map(|line| { + let mut cap = re.captures(line.as_ref()).unwrap(); + Blueprint { + id: extract(&cap, 1) as usize, + ore: Ore(extract(&cap, 2)), + clay: Ore(extract(&cap, 3)), + obsidian: (Ore(extract(&cap, 4)), Clay(extract(&cap, 5))), + geode: (Ore(extract(&cap, 6)), Obsidian(extract(&cap, 7))), + } + }) + .collect() +} + + +#[cfg(test)] +mod tests { + use super::*; + + static DATA: &[&str] = &[ + "Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 2 ore and 7 obsidian.", + "Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 3 ore and 12 obsidian.", + ]; + + #[test] + fn part1() { + assert_eq!(1, solve1(&parse_data(DATA))); + } + + #[test] + fn part2() { + assert_eq!(2, solve2(&parse_data(DATA))); + } +} diff --git a/2022/rust/src/solutions/mod.rs b/2022/rust/src/solutions/mod.rs index ff60e4a..66f2636 100644 --- a/2022/rust/src/solutions/mod.rs +++ b/2022/rust/src/solutions/mod.rs @@ -16,3 +16,4 @@ pub mod day15; pub mod day16; pub mod day17; pub mod day18; +pub mod day19;