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/part1/src/main.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 2022/day3/part1/src/main.rs (limited to '2022/day3/part1/src/main.rs') 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); +} -- cgit v1.2.3-70-g09d2