summaryrefslogtreecommitdiffstats
path: root/2022/day3/part1/src/main.rs
blob: 2de2ce8b81ada80012910e9eb8374a0f734a59e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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<char> = HashSet::from_iter(f.chars());
        let second: HashSet<char> = 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);
}