diff --git a/input/day7_example.txt b/input/day7_example.txt new file mode 100644 index 0000000..bcbb513 --- /dev/null +++ b/input/day7_example.txt @@ -0,0 +1,23 @@ +$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k \ No newline at end of file diff --git a/src/day7.rs b/src/day7.rs new file mode 100644 index 0000000..71006eb --- /dev/null +++ b/src/day7.rs @@ -0,0 +1,81 @@ +use crate::day_solver::DaySolver; + +use super::util; + +#[derive(Debug)] +enum FileSystemEntry { + File { + name: String, + size: usize + }, + Directory { + name: String, + } +} + +#[derive(Debug)] +enum Command { + LS { result: Vec }, + CD { target: String } +} + +pub struct Day7 { + commands: Vec +} + +impl Day7 { + + pub fn create() -> Self { + let lines = util::read_file("input/day7_example.txt"); + // let lines = util::read_file("input/day7.txt"); + + let mut lines_iter = lines.iter().peekable(); + let mut commands = Vec::new(); + while let Some(line) = lines_iter.next() { + if line == "$ ls" { + let mut result = Vec::new(); + if let Some(result_line) = lines_iter.peek() { + if !result_line.starts_with("$") { + if result_line.starts_with("dir") { + result.push(FileSystemEntry::Directory { + name: result_line.split_whitespace().skip(1).next().unwrap().to_string() + }) + } else { + let mut result_split = result_line.split_whitespace(); + result.push(FileSystemEntry::File { + size: result_split.next().unwrap().parse::().unwrap(), + name: result_split.next().unwrap().to_owned() + }); + } + lines_iter.next(); + } + } + commands.push(Command::LS { + result + }); + } else if line.starts_with("$ cd") { + commands.push(Command::CD { + target: line.chars().skip(5).collect() + }); + } + } + + println!("{:?}", commands); + // Put the input into the day struct + return Day7 { + commands + } + } +} + +impl DaySolver for Day7 { + + + fn solve_part1(&mut self) -> String { + return 0.to_string(); + } + + fn solve_part2(&mut self) -> String { + return 0.to_string(); + } +} diff --git a/src/main.rs b/src/main.rs index b0294d9..26f679b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use crate::day3::Day3; use crate::day4::Day4; use crate::day5::Day5; use crate::day6::Day6; +use crate::day7::Day7; use crate::day_solver::DaySolver; mod util; @@ -15,8 +16,9 @@ mod day3; mod day4; mod day5; mod day6; +mod day7; -const MAX_DAY: u8 = 5; +const MAX_DAY: u8 = 7; const DEFAULT_BENCHMARK_AMOUNT: u32 = 100; fn main() { @@ -86,6 +88,7 @@ fn build_day_solver(day: u8) -> Option> { 4 => Some(Box::new(Day4::create())), 5 => Some(Box::new(Day5::create())), 6 => Some(Box::new(Day6::create())), + 7 => Some(Box::new(Day7::create())), _ => None } }