From ef7e8df2825480f34c1034015a8221c09f6ebdf6 Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sun, 4 Dec 2022 14:19:12 +0300 Subject: 2022, day3: done --- 2022/day3/example | 6 + 2022/day3/input | 300 ++++++++++++++++++++++++++++++++++++++++++++ 2022/day3/part1/Cargo.toml | 9 ++ 2022/day3/part1/src/main.rs | 24 ++++ 2022/day3/part2/Cargo.toml | 9 ++ 2022/day3/part2/src/main.rs | 31 +++++ 6 files changed, 379 insertions(+) create mode 100644 2022/day3/example create mode 100644 2022/day3/input create mode 100644 2022/day3/part1/Cargo.toml create mode 100644 2022/day3/part1/src/main.rs create mode 100644 2022/day3/part2/Cargo.toml create mode 100644 2022/day3/part2/src/main.rs (limited to '2022/day3') diff --git a/2022/day3/example b/2022/day3/example new file mode 100644 index 0000000..f17e726 --- /dev/null +++ b/2022/day3/example @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw diff --git a/2022/day3/input b/2022/day3/input new file mode 100644 index 0000000..e5e3940 --- /dev/null +++ b/2022/day3/input @@ -0,0 +1,300 @@ +DPstqDdrsqdDtqrFDJDDrmtsJHflSJCLgCphgHHgRHJCRRff +BcBGcQzVBVZcvznTTTvZcGTpCRRRfRCggLflHlhhCZpZCj +vGQnQvnzTzNTTbVnzGBqMqwqDLdPtMmbwqqLLM +wLRFRqvFsFRjfrHddbdbjzdH +lcsnSJPSSVVlGmGrHzbbrGNrdzbz +mSmlnnPlmJmncVDSlSZSlmLBCvtwBvtLCqqswsDBCTWW +pfqPrPgmmhvqdlsdWq +nfjHLJfZcLbVtQWWtndhls +CzJJFLzRzfDwrmggpC +CWfllmlCDFlZZqMfmFBWmWLJVRLVwNNtRVGPpwtGpqbJ +jHndndndcj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argo.toml b/2022/day3/part1/Cargo.toml new file mode 100644 index 0000000..f14fe90 --- /dev/null +++ b/2022/day3/part1/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "part1" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +itertools = "0.10.5" diff --git a/2022/day3/part1/src/main.rs b/2022/day3/part1/src/main.rs new file mode 100644 index 0000000..2de2ce8 --- /dev/null +++ b/2022/day3/part1/src/main.rs @@ -0,0 +1,24 @@ +use std::collections::HashSet; + +fn main() { + let rucksacks: Vec<(&str, &str)> = include_str!("../../input") + .lines() + .map(|line| line.split_at(line.len() / 2)) + .collect(); + + let mut sum = 0; + for (f, s) in rucksacks { + let first: HashSet = HashSet::from_iter(f.chars()); + let second: HashSet = HashSet::from_iter(s.chars()); + + for x in first.intersection(&second) { + if x.is_lowercase() { + sum += *x as i16 - 96; + } else { + sum += *x as i16 - 38; + } + } + } + + println!("{}", sum); +} diff --git a/2022/day3/part2/Cargo.toml b/2022/day3/part2/Cargo.toml new file mode 100644 index 0000000..69fa504 --- /dev/null +++ b/2022/day3/part2/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "part2" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +itertools = "0.10.5" diff --git a/2022/day3/part2/src/main.rs b/2022/day3/part2/src/main.rs new file mode 100644 index 0000000..7139eb0 --- /dev/null +++ b/2022/day3/part2/src/main.rs @@ -0,0 +1,31 @@ +use itertools::Itertools; +use std::collections::HashMap; +use std::collections::HashSet; + +fn main() { + let mut sum = 0; + for group in &include_str!("../../input").lines().chunks(3) { + let mut membership: HashMap = HashMap::new(); + for rucksack in group { + let mut items: HashSet = HashSet::new(); + for item in &rucksack.chars().chunks(2) { + for c in item { + items.insert(c); + } + } + for c in &items { + *membership.entry(c.to_owned()).or_default() += 1; + } + } + for (item, value) in membership { + if value == 3 { + if item.is_lowercase() { + sum += item as i16 - 96; + } else { + sum += item as i16 - 38; + } + } + } + } + println!("{}", sum); +} -- cgit v1.2.3-70-g09d2