"Modular" approach
This commit is contained in:
parent
157b334b14
commit
1610660749
@ -1,5 +1,13 @@
|
|||||||
use std::collections::HashSet;
|
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 {
|
pub fn solve_part1(file_path: &str) -> i32 {
|
||||||
let binding =
|
let binding =
|
||||||
std::fs::read_to_string(file_path).expect("Please provide a text file as an argument.");
|
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 second = last.chars().collect::<HashSet<char>>();
|
||||||
let intersection = first.chars().collect::<HashSet<char>>();
|
let intersection = first.chars().collect::<HashSet<char>>();
|
||||||
let character = *intersection.intersection(&second).next().unwrap_or(&(0 as char)) as i32;
|
let character = *intersection.intersection(&second).next().unwrap_or(&(0 as char)) as i32;
|
||||||
if character >= ('a' as i32) {
|
character_to_code(character)
|
||||||
character - 96
|
|
||||||
} else {
|
|
||||||
character - 38
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.collect::<Vec<i32>>()
|
.collect::<Vec<i32>>()
|
||||||
.iter()
|
.iter()
|
||||||
|
Loading…
Reference in New Issue
Block a user