From 5d22d7975a9feb0dab7247b0b69351f50a58b324 Mon Sep 17 00:00:00 2001 From: gabe Date: Sat, 3 Dec 2022 01:26:51 -0600 Subject: [PATCH] Finished day 3. Annoyed at rusts hashset intersection function. --- Cargo.toml | 4 + src/day03/input.txt | 300 +++++++++++++++++++++++++++++++++++++++++ src/day03/part1.rs | 49 ++++++- src/day03/part2.rs | 80 ++++++++++- src/day03/solve.rs | 4 +- src/day03/utilities.rs | 76 ++++++++++- src/day04/input.txt | 0 src/day04/part1.rs | 15 +++ src/day04/part2.rs | 15 +++ src/day04/solve.rs | 14 ++ src/day04/utilities.rs | 17 +++ 11 files changed, 559 insertions(+), 15 deletions(-) create mode 100644 src/day04/input.txt create mode 100644 src/day04/part1.rs create mode 100644 src/day04/part2.rs create mode 100644 src/day04/solve.rs create mode 100644 src/day04/utilities.rs diff --git a/Cargo.toml b/Cargo.toml index 138cfa7..7be1f65 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,5 +22,9 @@ path="src/day02/solve.rs" name="day03" path="src/day03/solve.rs" +[[bin]] +name="day04" +path="src/day04/solve.rs" + [dependencies] regex="1" diff --git a/src/day03/input.txt b/src/day03/input.txt index e69de29..d0ad78f 100644 --- a/src/day03/input.txt +++ b/src/day03/input.txt @@ -0,0 +1,300 @@ +PcPlnShmrLmBnmcwBhrmcmbHNGFGpwdFFwGNjNbGqNHH +tzQfRJfWZZztWzVtCTfRzFZjpFjNZjGLHbdHLDdjpb +CCQTzRLzvQVVfRzJfMPsnBlglgPmBgPmvSrl +RMfvbbszHTsssFPzDQPggpQJPQ +NSNcqVtLVGgDlpQBClVB +hmStGNNLhjNrpWLGSjWrZssbZTMMvTfMnThbRRTs +fTrTPGTbfftWBBmLjrJL +DqHwVMqVplDslmlZmpHVwNnShWZFdBBdjWBtWtdtWJSSLS +MNslpDvVHlwsmpQRgQgCfTTcvcRQ +pBBhRgDsMsswprBhvgRglZtFGFFRqZtZmRtNqtZPPN +TdmmzzmdZdqdGFtF +nmS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jnZNLNmZvdtznntHHZJbBRGBRQWcJGbGsbsJRPQWT +MLmlMTPtQtMNlhbqbbqhflBB +rcrvjpSvScbRbBvbDBPG +ZZJzSHpzPrJzHFmMVMFmHCLNtV diff --git a/src/day03/part1.rs b/src/day03/part1.rs index 3ed0f00..ed23028 100644 --- a/src/day03/part1.rs +++ b/src/day03/part1.rs @@ -1,15 +1,58 @@ use crate::utilities::*; -pub fn part1() -> usize { - 0 +pub fn part1(input: &[Rucksack]) -> usize { + input + .iter() + .map(|rucksack| { + let intersection: Vec<&char> = rucksack.0.intersection(&rucksack.1).collect(); + assert!(intersection.len() == 1); + intersection[0] + }) + .map(find_char_score) + .sum() } #[cfg(test)] mod tests { + use std::collections::HashSet; use super::*; #[test] fn test_part1() { - assert_eq!(part1(), 0); + let input = vec![ + Rucksack( + HashSet::from(['v', 'J', 'r', 'w', 'p', 'W', 't', 'w', 'J', 'g', 'W', 'r']), + HashSet::from(['h', 'c', 's', 'F', 'M', 'M', 'f', 'F', 'F', 'h', 'F', 'p']), + ), + Rucksack( + HashSet::from([ + 'j', 'q', 'H', 'R', 'N', 'q', 'R', 'j', 'q', 'z', 'j', 'G', 'D', 'L', 'G', 'L', + ]), + HashSet::from([ + 'r', 's', 'F', 'M', 'f', 'F', 'Z', 'S', 'r', 'L', 'r', 'F', 'Z', 's', 'S', 'L', + ]), + ), + Rucksack( + HashSet::from(['P', 'm', 'm', 'd', 'z', 'q', 'P', 'r', 'V']), + HashSet::from(['v', 'P', 'w', 'w', 'T', 'W', 'B', 'w', 'g']), + ), + Rucksack( + HashSet::from([ + 'w', 'M', 'q', 'v', 'L', 'M', 'Z', 'H', 'h', 'H', 'M', 'v', 'w', 'L', 'H', + ]), + HashSet::from([ + 'j', 'b', 'v', 'c', 'j', 'n', 'n', 'S', 'B', 'n', 'v', 'T', 'Q', 'F', 'n', + ]), + ), + Rucksack( + HashSet::from(['t', 't', 'g', 'J', 't', 'R', 'G', 'J']), + HashSet::from(['Q', 'c', 't', 'T', 'Z', 't', 'Z', 'T']), + ), + Rucksack( + HashSet::from(['C', 'r', 'Z', 's', 'J', 's', 'P', 'P', 'Z', 's', 'G', 'z']), + HashSet::from(['w', 'w', 's', 'L', 'w', 'L', 'm', 'p', 'w', 'M', 'D', 'w']), + ), + ]; + assert_eq!(part1(&input), 157); } } diff --git a/src/day03/part2.rs b/src/day03/part2.rs index 4c7062c..b0bd75b 100644 --- a/src/day03/part2.rs +++ b/src/day03/part2.rs @@ -1,15 +1,89 @@ use crate::utilities::*; +use std::collections::HashSet; -pub fn part2() -> usize { - 0 +struct Group(HashSet, HashSet, HashSet); + +pub fn part2(input: &[Rucksack]) -> usize { + seperate_groups(input) + .iter() + .map(|group| { + //manual implementation of intersection because doing chained intersections is annoying... + group + .0 + .iter() + .filter(|c| group.1.contains(c)) + .filter(|c| group.2.contains(c)) + .map(|x| x.to_owned()) + .next() + .unwrap() + }).map(|c| find_char_score(&c)).sum() +} + +fn seperate_groups(input: &[Rucksack]) -> Vec { + let mut output: Vec = Vec::new(); + for group in input.chunks_exact(3) { + output.push(Group( + group[0] + .0 + .union(&group[0].1) + .map(|x| x.to_owned()) + .collect(), + group[1] + .0 + .union(&group[1].1) + .map(|x| x.to_owned()) + .collect(), + group[2] + .0 + .union(&group[2].1) + .map(|x| x.to_owned()) + .collect(), + )); + } + output } #[cfg(test)] mod tests { use super::*; + use std::collections::HashSet; #[test] fn test_part2() { - assert_eq!(part2(), 0); + let input = vec![ + Rucksack( + HashSet::from(['v', 'J', 'r', 'w', 'p', 'W', 't', 'w', 'J', 'g', 'W', 'r']), + HashSet::from(['h', 'c', 's', 'F', 'M', 'M', 'f', 'F', 'F', 'h', 'F', 'p']), + ), + Rucksack( + HashSet::from([ + 'j', 'q', 'H', 'R', 'N', 'q', 'R', 'j', 'q', 'z', 'j', 'G', 'D', 'L', 'G', 'L', + ]), + HashSet::from([ + 'r', 's', 'F', 'M', 'f', 'F', 'Z', 'S', 'r', 'L', 'r', 'F', 'Z', 's', 'S', 'L', + ]), + ), + Rucksack( + HashSet::from(['P', 'm', 'm', 'd', 'z', 'q', 'P', 'r', 'V']), + HashSet::from(['v', 'P', 'w', 'w', 'T', 'W', 'B', 'w', 'g']), + ), + Rucksack( + HashSet::from([ + 'w', 'M', 'q', 'v', 'L', 'M', 'Z', 'H', 'h', 'H', 'M', 'v', 'w', 'L', 'H', + ]), + HashSet::from([ + 'j', 'b', 'v', 'c', 'j', 'n', 'n', 'S', 'B', 'n', 'v', 'T', 'Q', 'F', 'n', + ]), + ), + Rucksack( + HashSet::from(['t', 't', 'g', 'J', 't', 'R', 'G', 'J']), + HashSet::from(['Q', 'c', 't', 'T', 'Z', 't', 'Z', 'T']), + ), + Rucksack( + HashSet::from(['C', 'r', 'Z', 's', 'J', 's', 'P', 'P', 'Z', 's', 'G', 'z']), + HashSet::from(['w', 'w', 's', 'L', 'w', 'L', 'm', 'p', 'w', 'M', 'D', 'w']), + ), + ]; + assert_eq!(part2(&input), 70); } } diff --git a/src/day03/solve.rs b/src/day03/solve.rs index c613d23..e4fc4b6 100644 --- a/src/day03/solve.rs +++ b/src/day03/solve.rs @@ -7,8 +7,8 @@ fn main() { let _structured_input = utilities::parse(_input); println!("Part One"); - println!("Result: {}", part1::part1()); + println!("Result: {}", part1::part1(&_structured_input)); println!("Part Two"); - println!("Result: {}", part2::part2()); + println!("Result: {}", part2::part2(&_structured_input)); } diff --git a/src/day03/utilities.rs b/src/day03/utilities.rs index e0d5990..d5196f3 100644 --- a/src/day03/utilities.rs +++ b/src/day03/utilities.rs @@ -1,6 +1,27 @@ -pub fn parse(input: &str) -> usize { - println!("{}", input); - 0 +use std::collections::HashSet; +#[derive(Debug, PartialEq, Eq)] +pub struct Rucksack(pub HashSet, pub HashSet); + +pub fn parse(input: &str) -> Vec { + input + .lines() + .map(|line| { + let (first, second) = line.split_at(line.len() / 2); + Rucksack(first.chars().collect(), second.chars().collect()) + }) + .collect() +} + +pub fn find_char_score(input: &char) -> usize { + static CHARS: [char; 52] = [ + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', + 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', + 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + ]; + CHARS + .iter() + .position(|character| character == input) + .unwrap()+1 } #[cfg(test)] @@ -9,9 +30,50 @@ mod tests { #[test] fn test_parse() { - let input = -"test" -; - assert_eq!(parse(input), 0); + let input = "vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw"; + assert_eq!( + parse(input), + vec![ + Rucksack( + HashSet::from(['v', 'J', 'r', 'w', 'p', 'W', 't', 'w', 'J', 'g', 'W', 'r']), + HashSet::from(['h', 'c', 's', 'F', 'M', 'M', 'f', 'F', 'F', 'h', 'F', 'p']) + ), + Rucksack( + HashSet::from([ + 'j', 'q', 'H', 'R', 'N', 'q', 'R', 'j', 'q', 'z', 'j', 'G', 'D', 'L', 'G', + 'L' + ]), + HashSet::from([ + 'r', 's', 'F', 'M', 'f', 'F', 'Z', 'S', 'r', 'L', 'r', 'F', 'Z', 's', 'S', + 'L' + ]) + ), + Rucksack( + HashSet::from(['P', 'm', 'm', 'd', 'z', 'q', 'P', 'r', 'V']), + HashSet::from(['v', 'P', 'w', 'w', 'T', 'W', 'B', 'w', 'g']) + ), + Rucksack( + HashSet::from([ + 'w', 'M', 'q', 'v', 'L', 'M', 'Z', 'H', 'h', 'H', 'M', 'v', 'w', 'L', 'H', + ]), + HashSet::from([ + 'j', 'b', 'v', 'c', 'j', 'n', 'n', 'S', 'B', 'n', 'v', 'T', 'Q', 'F', 'n', + ]) + ), + Rucksack( + HashSet::from(['t', 't', 'g', 'J', 't', 'R', 'G', 'J',]), + HashSet::from(['Q', 'c', 't', 'T', 'Z', 't', 'Z', 'T',]) + ), + Rucksack( + HashSet::from(['C', 'r', 'Z', 's', 'J', 's', 'P', 'P', 'Z', 's', 'G', 'z',]), + HashSet::from(['w', 'w', 's', 'L', 'w', 'L', 'm', 'p', 'w', 'M', 'D', 'w',]) + ), + ] + ); } } diff --git a/src/day04/input.txt b/src/day04/input.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/day04/part1.rs b/src/day04/part1.rs new file mode 100644 index 0000000..3ed0f00 --- /dev/null +++ b/src/day04/part1.rs @@ -0,0 +1,15 @@ +use crate::utilities::*; + +pub fn part1() -> usize { + 0 +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_part1() { + assert_eq!(part1(), 0); + } +} diff --git a/src/day04/part2.rs b/src/day04/part2.rs new file mode 100644 index 0000000..4c7062c --- /dev/null +++ b/src/day04/part2.rs @@ -0,0 +1,15 @@ +use crate::utilities::*; + +pub fn part2() -> usize { + 0 +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_part2() { + assert_eq!(part2(), 0); + } +} diff --git a/src/day04/solve.rs b/src/day04/solve.rs new file mode 100644 index 0000000..c613d23 --- /dev/null +++ b/src/day04/solve.rs @@ -0,0 +1,14 @@ +mod part1; +mod part2; +mod utilities; + +fn main() { + let _input = include_str!("./input.txt"); + let _structured_input = utilities::parse(_input); + + println!("Part One"); + println!("Result: {}", part1::part1()); + + println!("Part Two"); + println!("Result: {}", part2::part2()); +} diff --git a/src/day04/utilities.rs b/src/day04/utilities.rs new file mode 100644 index 0000000..e0d5990 --- /dev/null +++ b/src/day04/utilities.rs @@ -0,0 +1,17 @@ +pub fn parse(input: &str) -> usize { + println!("{}", input); + 0 +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_parse() { + let input = +"test" +; + assert_eq!(parse(input), 0); + } +}