1
0

Right answer !

This commit is contained in:
Pcornat 2022-12-05 21:55:28 +01:00
parent f4d2d3bf24
commit 5661ba3f2f
Signed by: Pcornat
GPG Key ID: 2F3932FF46D9ECA0
2 changed files with 11 additions and 6 deletions

View File

@ -16,6 +16,6 @@ fn main() {
{
let file_path = "prob3_part1.txt";
let max_part1 = prob3::solve_part1(file_path);
println!("{max_part1}");
println!("Solution for problem 3 part 1: {max_part1}");
}
}

View File

@ -3,7 +3,7 @@ use std::collections::HashSet;
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.");
let content = binding
binding
.lines()
.collect::<Vec<&str>>()
.iter()
@ -11,9 +11,14 @@ pub fn solve_part1(file_path: &str) -> i32 {
let (first, last) = item.split_at(item.len() / 2);
let second = last.chars().collect::<HashSet<char>>();
let intersection = first.chars().collect::<HashSet<char>>();
*intersection.intersection(&second).next().unwrap()
})
.collect::<Vec<char>>();
0
let character = *intersection.intersection(&second).next().unwrap() as i32;
if character >= ('a' as i32) {
character - 96
} else {
character - 38
}
})
.collect::<Vec<i32>>()
.iter()
.sum::<i32>()
}