summaryrefslogtreecommitdiffstats
path: root/2022/day3/part1/src
diff options
context:
space:
mode:
Diffstat (limited to '2022/day3/part1/src')
-rw-r--r--2022/day3/part1/src/main.rs24
1 files changed, 24 insertions, 0 deletions
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 @@
1use std::collections::HashSet;
2
3fn main() {
4 let rucksacks: Vec<(&str, &str)> = include_str!("../../input")
5 .lines()
6 .map(|line| line.split_at(line.len() / 2))
7 .collect();
8
9 let mut sum = 0;
10 for (f, s) in rucksacks {
11 let first: HashSet<char> = HashSet::from_iter(f.chars());
12 let second: HashSet<char> = HashSet::from_iter(s.chars());
13
14 for x in first.intersection(&second) {
15 if x.is_lowercase() {
16 sum += *x as i16 - 96;
17 } else {
18 sum += *x as i16 - 38;
19 }
20 }
21 }
22
23 println!("{}", sum);
24}