|
|
|
|
@ -17,6 +17,8 @@ pub struct Day5
|
|
|
|
|
run_mode: RunMode,
|
|
|
|
|
do_debug_prints: bool,
|
|
|
|
|
pub final_result: i32,
|
|
|
|
|
|
|
|
|
|
rules: Vec<Rule>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
@ -26,7 +28,7 @@ impl Day5
|
|
|
|
|
{
|
|
|
|
|
pub fn new() -> Day5
|
|
|
|
|
{
|
|
|
|
|
Day5 { data_set: DataSet::Test, run_mode: RunMode::FirstCase, do_debug_prints: false, final_result: 0 }
|
|
|
|
|
Day5 { data_set: DataSet::Test, run_mode: RunMode::FirstCase, do_debug_prints: false, final_result: 0, rules: vec![] }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn solve_first_case(self: &mut Self) -> String
|
|
|
|
|
@ -68,9 +70,31 @@ impl Solver for Day5
|
|
|
|
|
DataSet::Full => format!("{}/data/day5_input", dir),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let _data = utils::load_data(&data_filename);
|
|
|
|
|
let data = utils::load_data(&data_filename);
|
|
|
|
|
|
|
|
|
|
let mut split_pattern = "\n";
|
|
|
|
|
if data.contains("\r\n")
|
|
|
|
|
{
|
|
|
|
|
split_pattern = "\r\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let data_split = data.split(split_pattern);
|
|
|
|
|
for row in data_split
|
|
|
|
|
{
|
|
|
|
|
if row.contains("|")
|
|
|
|
|
{
|
|
|
|
|
self.rules.push(Rule::parse(row).expect(&format!("Failed to create rule from: {}", row) ));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Day5::init
|
|
|
|
|
if self.do_debug_prints
|
|
|
|
|
{
|
|
|
|
|
println!("Rules:");
|
|
|
|
|
for rule in &self.rules
|
|
|
|
|
{
|
|
|
|
|
println!("\tRule: {}|{}", rule.first, rule.second);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -90,4 +114,40 @@ impl Solver for Day5
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
// EXTRA STUFF
|
|
|
|
|
//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
|
struct Rule
|
|
|
|
|
{
|
|
|
|
|
first: i32,
|
|
|
|
|
second: i32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Rule
|
|
|
|
|
{
|
|
|
|
|
fn new(first: i32, second: i32) -> Rule
|
|
|
|
|
{
|
|
|
|
|
Rule { first, second }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn parse(input: &str) -> Result<Rule, &str>
|
|
|
|
|
{
|
|
|
|
|
if !input.contains("|")
|
|
|
|
|
{
|
|
|
|
|
return Err("Failed to parse rule: string does not contain \'|\'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let mut split = input.split("|");
|
|
|
|
|
let first = split.next().expect("Failed to parse rule: Could not properly split the input string");
|
|
|
|
|
let second = split.next().expect("Failed to parse rule: Could not properly split the input string");
|
|
|
|
|
|
|
|
|
|
let first = first.parse::<i32>().expect("Failed to parse rule: Could not convert value to i32");
|
|
|
|
|
let second = second.parse::<i32>().expect("Failed to parse rule: Could not convert value to i32");
|
|
|
|
|
|
|
|
|
|
Ok(Rule { first, second})
|
|
|
|
|
}
|
|
|
|
|
}
|