1
0
Fork 0

"Modular" approach

This commit is contained in:
Pcornat 2022-12-05 22:04:14 +01:00
parent 157b334b14
commit 1610660749
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0
1 changed files with 9 additions and 5 deletions

View File

@ -1,5 +1,13 @@
use std::collections::HashSet;
fn character_to_code(input: i32) -> i32 {
if input >= ('a' as i32) {
input - 96
} else {
input - 38
}
}
pub fn solve_part1(file_path: &str) -> i32 {
let binding =
std::fs::read_to_string(file_path).expect("Please provide a text file as an argument.");
@ -12,11 +20,7 @@ pub fn solve_part1(file_path: &str) -> i32 {
let second = last.chars().collect::<HashSet<char>>();
let intersection = first.chars().collect::<HashSet<char>>();
let character = *intersection.intersection(&second).next().unwrap_or(&(0 as char)) as i32;
if character >= ('a' as i32) {
character - 96
} else {
character - 38
}
character_to_code(character)
})
.collect::<Vec<i32>>()
.iter()