aoc22/src/day3.rs
2022-12-13 14:37:15 +01:00

26 lines
637 B
Rust

use std::collections::HashSet;
pub fn parse_rucksacks(input: &String) -> Vec<(HashSet<char>, HashSet<char>)> {
let lines = input.lines();
let mut rucksacks = Vec::new();
for line in lines {
let length = line.len();
assert!(length % 2 == 0);
let (first, second) = line.split_at(length / 2);
rucksacks.push((first.chars().collect(), second.chars().collect()));
}
rucksacks
}
pub fn priority(c: char) -> u32 {
assert!(c.is_ascii_alphabetic());
let ord = c as u32;
if c.is_ascii_lowercase() {
1 + ord - 'a' as u32
} else {
27 + ord - 'A' as u32
}
}