Day 3 - fmt and change I/O error msg
This commit is contained in:
parent
d032c76265
commit
ce0d539617
1 changed files with 7 additions and 8 deletions
15
src/d03.rs
15
src/d03.rs
|
@ -5,7 +5,7 @@ use std::fs;
|
|||
pub fn d03() {
|
||||
let path = "res/03/input.txt";
|
||||
|
||||
let contents = fs::read_to_string(path).expect("Should have been able to read the file");
|
||||
let contents = fs::read_to_string(path).expect("I/O error, wrong path?");
|
||||
|
||||
let cont_arr = contents.split("\n");
|
||||
|
||||
|
@ -45,15 +45,14 @@ pub fn d03() {
|
|||
|
||||
println!("Result 1: {}", result);
|
||||
|
||||
|
||||
// 2nd task
|
||||
// calculate results - find duplicates in each 3-rucksack groups and sum up
|
||||
let mut result = 0;
|
||||
for i in 0..rucksacks.len()/3 {
|
||||
for i in 0..rucksacks.len() / 3 {
|
||||
result += first_triplicate_value(
|
||||
&rucksacks[i*3],
|
||||
&rucksacks[i*3 + 1],
|
||||
&rucksacks[i*3 + 2]
|
||||
&rucksacks[i * 3],
|
||||
&rucksacks[i * 3 + 1],
|
||||
&rucksacks[i * 3 + 2],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -88,7 +87,7 @@ fn first_triplicate_value(vec1: &Vec<i32>, vec2: &Vec<i32>, vec3: &Vec<i32>) ->
|
|||
vec1.iter().for_each(|i| {
|
||||
vec_set1.insert(*i);
|
||||
});
|
||||
|
||||
|
||||
vec2.iter().for_each(|i| {
|
||||
vec_set2.insert(*i);
|
||||
});
|
||||
|
@ -101,4 +100,4 @@ fn first_triplicate_value(vec1: &Vec<i32>, vec2: &Vec<i32>, vec3: &Vec<i32>) ->
|
|||
});
|
||||
|
||||
res
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue