diff --git a/src/cli/commands/day004.rs b/src/cli/commands/day004.rs index 8f1a4c9..7d7129c 100644 --- a/src/cli/commands/day004.rs +++ b/src/cli/commands/day004.rs @@ -1,8 +1,55 @@ -use crate::cli::PathBuf; use crate::util::read_lines; +use std::fs::File; +use std::io::{BufReader, Lines}; +use std::path::PathBuf; + +fn part1(lines: Lines>) { + let mut full_containt: u32 = 0; + let mut overlapping: u32 = 0; + for line in lines { + let temp_line = line; + let mut team: Vec = Vec::new(); + temp_line + .unwrap() + .split(",") + .collect::>() + .iter() + .for_each(|s| { + s.split("-") + .into_iter() + .for_each(|s| team.push(s.parse::().unwrap())) + }); + let t1_start: &u32 = team.get(0).unwrap(); + let t1_end: &u32 = team.get(1).unwrap(); + let t2_start: &u32 = team.get(2).unwrap(); + let t2_end: &u32 = team.get(3).unwrap(); + if (t1_start >= t2_start && t1_end <= t2_end) + || (t2_start >= t1_start && t2_end <= t1_end) + || (t1_start == t2_end &&t2_start == t2_end) + || (t1_end == t2_end && t2_start == t2_end) + { + println!( + "Gruppe full: {:?}-{:?}, {:?}-{:?}", + t1_start, t1_end, t2_start, t2_end + ); + //println!("{:?}", team); + full_containt += 1; + } else if (t1_start < t2_end && t1_end < t2_end) || (t2_start >= t1_start) { + println!( + "Gruppe part: {:?}-{:?}, {:?}-{:?}", + t1_start, t1_end, t2_start, t2_end + ); + overlapping += 1; + } + } + + println!("full {:?}", full_containt); + println!("part {:?}", overlapping); + println!("total {:?}", full_containt + overlapping); +} pub fn subcmd_day004(file: &Option, alt: &bool) { if let Ok(lines) = read_lines(file.as_ref().unwrap().as_path()) { - + part1(lines); } }