Day 3 - fmt and change I/O error msg

This commit is contained in:
Jonathan Flueren 2022-12-03 14:52:54 +01:00
parent d032c76265
commit ce0d539617

View file

@ -5,7 +5,7 @@ use std::fs;
pub fn d03() { pub fn d03() {
let path = "res/03/input.txt"; 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"); let cont_arr = contents.split("\n");
@ -45,15 +45,14 @@ pub fn d03() {
println!("Result 1: {}", result); println!("Result 1: {}", result);
// 2nd task // 2nd task
// calculate results - find duplicates in each 3-rucksack groups and sum up // calculate results - find duplicates in each 3-rucksack groups and sum up
let mut result = 0; let mut result = 0;
for i in 0..rucksacks.len()/3 { for i in 0..rucksacks.len() / 3 {
result += first_triplicate_value( result += first_triplicate_value(
&rucksacks[i*3], &rucksacks[i * 3],
&rucksacks[i*3 + 1], &rucksacks[i * 3 + 1],
&rucksacks[i*3 + 2] &rucksacks[i * 3 + 2],
); );
} }