From 9c43a0f50e10a9dabb148381495fad8cb48b7c5a Mon Sep 17 00:00:00 2001 From: Anthony Cicchetti Date: Sun, 4 Dec 2022 12:41:55 -0500 Subject: [PATCH] Day 3 Part 2 --- day_02/src/parser/part_02.rs | 32 ++-- day_03/Cargo.toml | 3 + day_03/input/part1 | 300 +++++++++++++++++++++++++++++++++++ day_03/src/lib.rs | 48 ++++-- 4 files changed, 360 insertions(+), 23 deletions(-) create mode 100644 day_03/input/part1 diff --git a/day_02/src/parser/part_02.rs b/day_02/src/parser/part_02.rs index 882cfd3..ffcab84 100644 --- a/day_02/src/parser/part_02.rs +++ b/day_02/src/parser/part_02.rs @@ -72,20 +72,24 @@ mod tests { #[test] fn example_sequence_parsed() { assert_eq!( - Ok(("", vec![ - Trick { - against: Hand::Rock, - thrown: Hand::Rock, - }, - Trick { - against: Hand::Paper, - thrown: Hand::Rock, - }, - Trick { - against: Hand::Scissors, - thrown: Hand::Rock, - } - ])), sequence_parser("A Y\nB X\nC Z") + Ok(( + "", + vec![ + Trick { + against: Hand::Rock, + thrown: Hand::Rock, + }, + Trick { + against: Hand::Paper, + thrown: Hand::Rock, + }, + Trick { + against: Hand::Scissors, + thrown: Hand::Rock, + } + ] + )), + sequence_parser("A Y\nB X\nC Z") ) } } diff --git a/day_03/Cargo.toml b/day_03/Cargo.toml index ed3125f..7fc0b1c 100644 --- a/day_03/Cargo.toml +++ b/day_03/Cargo.toml @@ -6,5 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +chunk_iter = "0.1.5" common = {path = '../common'} +intersection = "1.0.0" +itertools = "0.10.5" phf = { version = "0.11.1", features = ["macros"] } diff --git a/day_03/input/part1 b/day_03/input/part1 new file mode 100644 index 0000000..606e5e6 --- /dev/null +++ b/day_03/input/part1 @@ -0,0 +1,300 @@ +PnJJfVPBcfVnnPnBFFcggttrtgCrjDtSjzSS +llWlLbmmdLLwLbqGdmTmbZfCQtzrMQfrjSzrtSr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dzLLjHwGplflfrfPcgtflgLFLlcrcc +hqhDMSSqWZsDMVWTVWmTcglglflFVflFrpPtggcv +sshbJsTsqWMbqNWbhbzzjzGBQjCJQnzwmzBw +QnpfLpbLfGbvgjHzjgmNRqbz +SSMBMZDwMwFsqgSPPmHlHj +BhMFJhMBddDMFcTdMVddrQfvrnCqnCffpqnVCLtC +lhrTZNJZjCRjSCvRSlTSLlrvFnMHQhVDnqnmqqqmQqPDHmqF +wcpGdtwtwzcbpzggCFPMqtMQmQqmVqHP +bBfwgWbfwBdGpppGGGbcBsTRLlZTZsTRTsRNZClJsvZL +nJLgNcQDNMlQHMvCbv +zphFpmTszmwhGGFhhtppNfffVlvZvHCCVZzbfzvS +mTTsmTRGstsFhWwtWjPRdjnJdjJnLjcLNd +MfBDjllflHLTpDhhppDDbp +NZBBnGJNnNPWTcTTmVhZCh +PSzgSgwrnzrSzBGJSJrSLQqfMHQfqgRgfjHLljll +RgbNmBbqgWHWRNRqHtcMlMwJJjcDtVlD +SzpFLGPddSGnnSLQZLtJJcclDlVjDQwMhDcc +LtTZCTttRqqqvqTN diff --git a/day_03/src/lib.rs b/day_03/src/lib.rs index 8385d3f..bd85638 100644 --- a/day_03/src/lib.rs +++ b/day_03/src/lib.rs @@ -1,8 +1,11 @@ -use std::collections::HashSet; +use chunk_iter::ChunkIter; use common::{Day, Part}; use phf::phf_map; +use std::collections::HashSet; +use intersection::hash_set; +use itertools::{Itertools, kmerge}; -static VALUES: phf::Map = phf_map!{ +static VALUES: phf::Map = phf_map! { 'a' => 1, 'b' => 2, 'c' => 3, @@ -68,18 +71,35 @@ pub fn run_day_and_part(day: Day, part: Part, inp: &str) -> usize { fn part01_parse(inp: &str) -> Vec { let inp = inp.split_whitespace(); inp.map(|row: &str| row.split_at(row.len() / 2)) - .map(|(left, right): (&str, &str)| (HashSet::from_iter(left.chars()), - HashSet::from_iter(right.chars()))) - .map(|(left, right): (HashSet, HashSet)| *left.intersection(&right).next().unwrap()) + .map(|(left, right): (&str, &str)| { + ( + HashSet::from_iter(left.chars()), + HashSet::from_iter(right.chars()), + ) + }) + .map(|(left, right): (HashSet, HashSet)| { + *left.intersection(&right).next().unwrap() + }) .map(|i: char| VALUES[&i]) .collect::>() } fn part02_parse(inp: &str) -> Vec { - vec![] + let inp = inp.split_whitespace(); + ChunkIter::chunks::<3>(inp.map(|it| HashSet::from_iter(it.chars()))) + .map(|it| match it { + [first, second, third] => dbg!((first, second, third)), + }) + .map::( + |(first, second, third): (HashSet, HashSet, HashSet)| { + *hash_set::intersection(vec![first,second,third]).iter().next().unwrap() + }, + ) + .map(|it| dbg!(it)) + .map(|i: char| VALUES[&i]) + .collect() } - #[cfg(test)] mod tests { use super::*; @@ -92,7 +112,17 @@ PmmdzqPrVvPwwTWBwg wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn ttgJtRGJQctTZtZT CrZsJsPPZsGzwwsLwLmpwMDw"#; - let result = 2 + 2 ; - assert_eq!(result, 4); + assert_eq!(part01_parse(input), vec![16, 38, 42, 22, 20, 19]); + } + + #[test] + fn part_02_example_works() { + let input = r#"vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw"#; + assert_eq!(part02_parse(input), vec![18, 52]) } }