diff --git a/2022/day07-part1/Cargo.toml b/2022/day07-part1/Cargo.toml new file mode 100644 index 0000000..3e8c958 --- /dev/null +++ b/2022/day07-part1/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day07-part1" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2022/day07-part1/src/main.rs b/2022/day07-part1/src/main.rs new file mode 100644 index 0000000..0df5291 --- /dev/null +++ b/2022/day07-part1/src/main.rs @@ -0,0 +1,65 @@ +use std::{cell::RefCell, rc::Rc}; + +// Custom data structure +#[derive(Copy, Clone, Debug)] +enum NodeType { + File, + Directory, +} + +use NodeType::*; + +struct Node { + node_type: NodeType, + name: String, + size: usize, + children: Vec>>, +} + +impl Node { + fn new(node_type: NodeType, name: &str, size: usize) -> Rc> { + Rc::new(RefCell::new(Node { + node_type, + name: String::from(name), + size, + children: Vec::new(), + })) + } +} + +fn main() { + // Use command line arguments to specify the input filename. + let args: Vec = std::env::args().collect(); + if args.len() < 2 { + panic!("Usage: ./main \nNo input file provided. Exiting."); + } + + // Next, read the contents of the input file into a string for easier processing. + let input = std::fs::read_to_string(&args[1]).expect("Error opening file"); + // Line-by-line processing is easiest. + let input = input.lines(); + + // --- TASK BEGIN --- + let mut result = 0; + + // Set up our filesystem, starting with the root directory as the root node. + let root = Node::new(Directory, "/", 0); + + // Also set up a + let current = root; + + // Read line by line + for line in input { + // Split any incoming line by spaces, makes our life easier down the line. + let line = line.split(' ').collect::>(); + + // First of all, differentiate between command and list item. + if line[0] == "$" { + + } else { + println!("item"); + } + } + + println!("Result: {}", result); +}