diff --git a/src/prob3/mod.rs b/src/prob3/mod.rs index 175594a..783354d 100644 --- a/src/prob3/mod.rs +++ b/src/prob3/mod.rs @@ -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::>(); let intersection = first.chars().collect::>(); 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::>() .iter()