diff options
author | Yigit Sever | 2022-12-04 14:19:12 +0300 |
---|---|---|
committer | Yigit Sever | 2022-12-04 14:19:12 +0300 |
commit | ef7e8df2825480f34c1034015a8221c09f6ebdf6 (patch) | |
tree | 9ce122c24814d377d993a984178bfa42eac904df /2022/day3/part1/src | |
parent | 9725ad032ce7d42f01119d8334d420a398d2c855 (diff) | |
download | aoc-ef7e8df2825480f34c1034015a8221c09f6ebdf6.tar.gz aoc-ef7e8df2825480f34c1034015a8221c09f6ebdf6.tar.bz2 aoc-ef7e8df2825480f34c1034015a8221c09f6ebdf6.zip |
2022, day3: done
Diffstat (limited to '2022/day3/part1/src')
-rw-r--r-- | 2022/day3/part1/src/main.rs | 24 |
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 @@ | |||
1 | use std::collections::HashSet; | ||
2 | |||
3 | fn 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 | } | ||