Start day 7 part 1

This commit is contained in:
Timothy Warren 2022-12-07 10:44:27 -05:00
parent fd789caa45
commit 34a7dd17fa
4 changed files with 1170 additions and 0 deletions

7
day7/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "day7"
version = "0.1.0"

8
day7/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "day7"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

1083
day7/src/input.txt Normal file

File diff suppressed because it is too large Load Diff

72
day7/src/main.rs Normal file
View File

@ -0,0 +1,72 @@
use std::collections::HashMap;
const MAX_DIR_SIZE: u128 = 100_000;
#[derive(Debug)]
struct File {
name: String,
size: u128,
}
impl File {
fn new<T: ToString + ?Sized>(raw_line: &T) -> Self {
let raw = raw_line.to_string();
let parts: Vec<&str> = raw.split(' ').collect();
let size = parts[0].parse::<u128>().unwrap();
let name = parts[1].to_string();
File { name, size }
}
}
// ----------------------------------------------------------------------------
#[derive(Debug)]
struct Dir {
parent: String,
name: String,
files: Vec<File>,
dirs: Vec<String>,
}
impl Dir {
fn new<T: ToString + ?Sized>(parent: &T, name: &T) -> Self {
Dir {
parent: parent.to_string(),
name: name.to_string(),
files: Vec::new(),
dirs: Vec::new(),
}
}
fn get_loose_files_size(&self) -> u128 {
self.files
.iter()
.map(|file| file.size)
.reduce(|accum, item| accum + item)
.unwrap()
}
}
// ----------------------------------------------------------------------------
struct DirMap {
current_path: String,
map: HashMap<String, Dir>,
}
impl DirMap {
fn new() -> Self {
DirMap {
current_path: "/".to_string(),
map: HashMap::new(),
}
}
}
// ----------------------------------------------------------------------------
fn main() {
let file_str = include_str!("input.txt");
let path_map = DirMap::new();
}