summaryrefslogtreecommitdiffstats
path: root/2022/day3/part1/src/main.rs
diff options
context:
space:
mode:
authorYigit Sever2022-12-04 14:19:12 +0300
committerYigit Sever2022-12-04 14:19:12 +0300
commitef7e8df2825480f34c1034015a8221c09f6ebdf6 (patch)
tree9ce122c24814d377d993a984178bfa42eac904df /2022/day3/part1/src/main.rs
parent9725ad032ce7d42f01119d8334d420a398d2c855 (diff)
downloadaoc-ef7e8df2825480f34c1034015a8221c09f6ebdf6.tar.gz
aoc-ef7e8df2825480f34c1034015a8221c09f6ebdf6.tar.bz2
aoc-ef7e8df2825480f34c1034015a8221c09f6ebdf6.zip
2022, day3: done
Diffstat (limited to '2022/day3/part1/src/main.rs')
-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}