day 07 in progress. Have data structure skeleton down.

This commit is contained in:
gabe 2022-12-07 01:26:48 -06:00
parent e0ba8a18f1
commit 4c11c4df3e
8 changed files with 1218 additions and 20 deletions

View file

@ -34,6 +34,10 @@ path="src/day05/solve.rs"
name="day06"
path="src/day06/solve.rs"
[[bin]]
name="day07"
path="src/day07/solve.rs"
[dependencies]
regex="1"
once_cell = "1.16.0"

21
src/day07/fileTree.rs Normal file
View file

@ -0,0 +1,21 @@
use std::{rc::{Weak, Rc}, cell::RefCell};
#[derive(Debug)]
pub struct Dir {
parent: Option<Weak<RefCell<Dir>>>,
name: String,
children: Vec<Rc<RefCell<FileOrDir>>>
}
#[derive(Debug)]
pub struct File{
dir: Weak<RefCell<Dir>>,
size: usize,
name: String
}
#[derive(Debug)]
pub enum FileOrDir{
File(File),
Dir(Dir),
}

File diff suppressed because it is too large Load diff

155
src/day07/parser.rs Normal file
View file

@ -0,0 +1,155 @@
use crate::fileTree::*;
use once_cell::sync::Lazy;
use regex::Regex;
#[derive(Debug, PartialEq, Eq)]
pub enum Command {
CdRoot,
CdUp,
Cd(String),
Ls(Vec<LsEntry>),
}
#[derive(Debug, PartialEq, Eq)]
pub enum LsEntry {
Dir(String),
File(ParseFile),
}
#[derive(Debug, PartialEq, Eq)]
pub struct ParseFile {
size: usize,
name: String,
}
pub fn parse(input: &str) -> Dir {
unimplemented!()
}
pub fn parse_to_tree(input: Vec<Command>) -> Dir {
unimplemented!()
}
//parses a single line
pub fn parse_to_commands(input: &str) -> Vec<Command> {
static PARSE_COMMAND_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^$").unwrap());
unimplemented!()
}
#[cfg(test)]
mod tests {
use super::*;
/* #[test]
fn test_parse() {
let input = "$ 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";
assert_eq!(parse(input), 0);
} */
#[test]
fn test_parse_to_commands() {
let input = "$ 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";
assert_eq!(
parse_to_commands(input),
vec![
Command::CdRoot,
Command::Ls(vec![
LsEntry::Dir(String::from("a")),
LsEntry::File(ParseFile {
size: 14848514,
name: String::from("b.txt")
}),
LsEntry::File(ParseFile {
size: 8504156,
name: String::from("c.dat")
}),
LsEntry::Dir(String::from("d"))
]),
Command::Cd(String::from("a")),
Command::Ls(vec![
LsEntry::Dir(String::from("e")),
LsEntry::File(ParseFile {
size: 29116,
name: String::from("f")
}),
LsEntry::File(ParseFile {
size: 2557,
name: String::from("g")
}),
LsEntry::File(ParseFile {
size: 62596,
name: String::from("h.lst")
}),
]),
Command::Cd(String::from("e")),
Command::Ls(vec![LsEntry::File(ParseFile {
size: 484,
name: String::from("i")
}),]),
Command::CdUp,
Command::CdUp,
Command::Cd(String::from("d")),
Command::Ls(vec![
LsEntry::File(ParseFile {
size: 4060174,
name: String::from("j")
}),
LsEntry::File(ParseFile {
size: 8033020,
name: String::from("d.log")
}),
LsEntry::File(ParseFile {
size: 5626152,
name: String::from("d.ext")
}),
LsEntry::File(ParseFile {
size: 7214296,
name: String::from("k")
}),
]),
]
)
}
}

View file

@ -1,4 +1,5 @@
use crate::utilities::*;
use crate::fileTree::*;
use crate::parser::*;
pub fn part1() -> usize {
unimplemented!()

View file

@ -1,4 +1,5 @@
use crate::utilities::*;
use crate::fileTree::*;
use crate::parser::*;
pub fn part2() -> usize {
unimplemented!()

View file

@ -1,10 +1,11 @@
mod part1;
mod part2;
mod utilities;
mod parser;
mod fileTree;
fn main() {
let _input = include_str!("./input.txt");
let _structured_input = utilities::parse(_input);
let _structured_input = parser::parse(_input);
println!("Part One");
println!("Result: {}", part1::part1());

View file

@ -1,16 +0,0 @@
pub fn parse(input: &str) -> usize {
unimplemented!()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse() {
let input =
"test"
;
assert_eq!(parse(input), 0);
}
}