Right answer !
This commit is contained in:
parent
f4d2d3bf24
commit
5661ba3f2f
@ -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}");
|
||||
}
|
||||
}
|
||||
|
@ -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>()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user