day 2: input read from file
This commit is contained in:
1000
assets/day_2_reports_input
Normal file
1000
assets/day_2_reports_input
Normal file
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,6 @@ pub fn historian_hysteria() {
|
|||||||
println!("The similarity is: {similarity}");
|
println!("The similarity is: {similarity}");
|
||||||
|
|
||||||
// Monday 02
|
// Monday 02
|
||||||
let safe_report_count = mon_02::check_reports_safety("");
|
let safe_report_count = mon_02::check_reports_safety("./assets/day_2_reports_input");
|
||||||
println!("There are {safe_report_count} safe reports");
|
println!("There are {safe_report_count} safe reports");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,9 @@
|
|||||||
use utils::calc_distance;
|
use utils::{calc_distance, read_report_list};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn check_reports_safety(input: &str) -> ReportSafety {
|
pub fn check_reports_safety(input: &str) -> ReportSafety {
|
||||||
let report_list: [[Report; 5]; 6] = [
|
let report_list = read_report_list(input);
|
||||||
[7, 6, 4, 2, 1],
|
|
||||||
[1, 2, 7, 8, 9],
|
|
||||||
[9, 7, 6, 2, 1],
|
|
||||||
[1, 3, 2, 4, 5],
|
|
||||||
[8, 6, 4, 4, 1],
|
|
||||||
[1, 3, 6, 7, 9],
|
|
||||||
];
|
|
||||||
|
|
||||||
let mut safe_count: ReportSafety = 0;
|
let mut safe_count: ReportSafety = 0;
|
||||||
|
|
||||||
@@ -25,6 +18,7 @@ pub fn check_reports_safety(input: &str) -> ReportSafety {
|
|||||||
|
|
||||||
let mut safe = true;
|
let mut safe = true;
|
||||||
let initial_direction: ReportDirection = get_report_direction(&report[0..=1]);
|
let initial_direction: ReportDirection = get_report_direction(&report[0..=1]);
|
||||||
|
let mut problems_damped_count = 0;
|
||||||
|
|
||||||
'report_check: for index in 1..report.len() {
|
'report_check: for index in 1..report.len() {
|
||||||
let prev = index - 1;
|
let prev = index - 1;
|
||||||
@@ -36,9 +30,12 @@ pub fn check_reports_safety(input: &str) -> ReportSafety {
|
|||||||
|| distance > 3
|
|| distance > 3
|
||||||
|| direction != initial_direction
|
|| direction != initial_direction
|
||||||
{
|
{
|
||||||
|
if report_problem_dampener(&report) == false {
|
||||||
safe = false;
|
safe = false;
|
||||||
break 'report_check;
|
break 'report_check;
|
||||||
}
|
}
|
||||||
|
problems_damped_count += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if safe {
|
if safe {
|
||||||
@@ -49,6 +46,9 @@ pub fn check_reports_safety(input: &str) -> ReportSafety {
|
|||||||
safe_count
|
safe_count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NOTE: the simples solition is by brute force...
|
||||||
|
fn report_problem_dampener(report: &Vec<Report>) -> bool {}
|
||||||
|
|
||||||
// FIXME: this is not a good function, since may try to access an invalid index
|
// FIXME: this is not a good function, since may try to access an invalid index
|
||||||
fn get_report_direction(report: &[Report]) -> ReportDirection {
|
fn get_report_direction(report: &[Report]) -> ReportDirection {
|
||||||
if report[1] - report[0] > 0 {
|
if report[1] - report[0] > 0 {
|
||||||
|
|||||||
@@ -17,7 +17,20 @@ pub fn read_id_lists(input: &str) -> (Vec<Id>, Vec<Id>) {
|
|||||||
return (list_1, list_2);
|
return (list_1, list_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_report_list(input: &str) {}
|
pub fn read_report_list(input: &str) -> Vec<Vec<Report>> {
|
||||||
|
let mut report_list: Vec<Vec<Report>> = vec![];
|
||||||
|
|
||||||
|
for report in read_to_string(input).unwrap().lines() {
|
||||||
|
let level_list = report.split(" ");
|
||||||
|
let mut report_vec: Vec<Report> = vec![];
|
||||||
|
for level in level_list {
|
||||||
|
report_vec.push(level.parse::<Report>().unwrap());
|
||||||
|
}
|
||||||
|
report_list.push(report_vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
report_list
|
||||||
|
}
|
||||||
|
|
||||||
pub fn calc_distance<T>(num_1: T, num_2: T) -> T
|
pub fn calc_distance<T>(num_1: T, num_2: T) -> T
|
||||||
where
|
where
|
||||||
|
|||||||
Reference in New Issue
Block a user