From 305ec1f29d723d2d0f119ddcd2ac5533e402aa5b Mon Sep 17 00:00:00 2001 From: Anson Date: Tue, 11 Oct 2022 21:15:55 -0600 Subject: [PATCH] refactor organization of repo --- .gitignore | 6 +++- day2/rust/Cargo.toml => Cargo.toml | 3 +- day1/.devcontainer/Dockerfile | 9 ------ day1/.devcontainer/devcontainer.json | 46 ---------------------------- day1/rust/Cargo.lock | 7 ----- day1/rust/Cargo.toml | 8 ----- day2/.devcontainer/Dockerfile | 9 ------ day2/.devcontainer/devcontainer.json | 46 ---------------------------- day3/rust/Cargo.toml | 8 ----- day4/rust/Cargo.toml | 8 ----- day5/rust/Cargo.toml | 9 ------ debug.log | 2 -- day1/input.txt => inputs/day1.txt | 0 day2/input.txt => inputs/day2.txt | 0 day3/input.txt => inputs/day3.txt | 0 day4/input.txt => inputs/day4.txt | 0 day5/input.txt => inputs/day5.txt | 0 day1/rust/src/main.rs => src/day1.rs | 9 +++--- day2/rust/src/main.rs => src/day2.rs | 9 +++--- day3/rust/src/main.rs => src/day3.rs | 9 +++--- day4/rust/src/main.rs => src/day4.rs | 9 +++--- day5/rust/src/main.rs => src/day5.rs | 7 +++-- src/main.rs | 14 +++++++++ 23 files changed, 45 insertions(+), 173 deletions(-) rename day2/rust/Cargo.toml => Cargo.toml (81%) delete mode 100644 day1/.devcontainer/Dockerfile delete mode 100644 day1/.devcontainer/devcontainer.json delete mode 100644 day1/rust/Cargo.lock delete mode 100644 day1/rust/Cargo.toml delete mode 100644 day2/.devcontainer/Dockerfile delete mode 100644 day2/.devcontainer/devcontainer.json delete mode 100644 day3/rust/Cargo.toml delete mode 100644 day4/rust/Cargo.toml delete mode 100644 day5/rust/Cargo.toml delete mode 100644 debug.log rename day1/input.txt => inputs/day1.txt (100%) rename day2/input.txt => inputs/day2.txt (100%) rename day3/input.txt => inputs/day3.txt (100%) rename day4/input.txt => inputs/day4.txt (100%) rename day5/input.txt => inputs/day5.txt (100%) rename day1/rust/src/main.rs => src/day1.rs (76%) rename day2/rust/src/main.rs => src/day2.rs (83%) rename day3/rust/src/main.rs => src/day3.rs (90%) rename day4/rust/src/main.rs => src/day4.rs (58%) rename day5/rust/src/main.rs => src/day5.rs (79%) create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore index 5208977..e8c940d 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,8 @@ Cargo.lock **/*.rs.bk # MSVC Windows builds of rustc generate these, which store debugging information -*.pdb \ No newline at end of file +*.pdb + +# Added by cargo + +/target diff --git a/day2/rust/Cargo.toml b/Cargo.toml similarity index 81% rename from day2/rust/Cargo.toml rename to Cargo.toml index 1ec6963..fb3b91a 100644 --- a/day2/rust/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,9 @@ [package] -name = "rust" +name = "aoc2021" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +itertools = "0.10.3" \ No newline at end of file diff --git a/day1/.devcontainer/Dockerfile b/day1/.devcontainer/Dockerfile deleted file mode 100644 index 31c18c9..0000000 --- a/day1/.devcontainer/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/rust/.devcontainer/base.Dockerfile - -# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye -ARG VARIANT="buster" -FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT} - -# [Optional] Uncomment this section to install additional packages. -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends diff --git a/day1/.devcontainer/devcontainer.json b/day1/.devcontainer/devcontainer.json deleted file mode 100644 index cfcfbe5..0000000 --- a/day1/.devcontainer/devcontainer.json +++ /dev/null @@ -1,46 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/rust -{ - "name": "Rust", - "build": { - "dockerfile": "Dockerfile", - "args": { - // Use the VARIANT arg to pick a Debian OS version: buster, bullseye - // Use bullseye when on local on arm64/Apple Silicon. - "VARIANT": "buster" - } - }, - "runArgs": [ - "--cap-add=SYS_PTRACE", - "--security-opt", - "seccomp=unconfined" - ], - - // Set *default* container specific settings.json values on container create. - "settings": { - "lldb.executable": "/usr/bin/lldb", - // VS Code don't watch files under ./target - "files.watcherExclude": { - "**/target/**": true - }, - "rust-analyzer.checkOnSave.command": "clippy" - }, - - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "vadimcn.vscode-lldb", - "mutantdino.resourcemonitor", - "matklad.rust-analyzer", - "tamasfe.even-better-toml", - "serayuzgur.crates" - ], - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "rustc --version", - - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" -} diff --git a/day1/rust/Cargo.lock b/day1/rust/Cargo.lock deleted file mode 100644 index b21cc6a..0000000 --- a/day1/rust/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "rust" -version = "0.1.0" diff --git a/day1/rust/Cargo.toml b/day1/rust/Cargo.toml deleted file mode 100644 index 1ec6963..0000000 --- a/day1/rust/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "rust" -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/day2/.devcontainer/Dockerfile b/day2/.devcontainer/Dockerfile deleted file mode 100644 index 31c18c9..0000000 --- a/day2/.devcontainer/Dockerfile +++ /dev/null @@ -1,9 +0,0 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/rust/.devcontainer/base.Dockerfile - -# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye -ARG VARIANT="buster" -FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT} - -# [Optional] Uncomment this section to install additional packages. -# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ -# && apt-get -y install --no-install-recommends diff --git a/day2/.devcontainer/devcontainer.json b/day2/.devcontainer/devcontainer.json deleted file mode 100644 index cfcfbe5..0000000 --- a/day2/.devcontainer/devcontainer.json +++ /dev/null @@ -1,46 +0,0 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: -// https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/rust -{ - "name": "Rust", - "build": { - "dockerfile": "Dockerfile", - "args": { - // Use the VARIANT arg to pick a Debian OS version: buster, bullseye - // Use bullseye when on local on arm64/Apple Silicon. - "VARIANT": "buster" - } - }, - "runArgs": [ - "--cap-add=SYS_PTRACE", - "--security-opt", - "seccomp=unconfined" - ], - - // Set *default* container specific settings.json values on container create. - "settings": { - "lldb.executable": "/usr/bin/lldb", - // VS Code don't watch files under ./target - "files.watcherExclude": { - "**/target/**": true - }, - "rust-analyzer.checkOnSave.command": "clippy" - }, - - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "vadimcn.vscode-lldb", - "mutantdino.resourcemonitor", - "matklad.rust-analyzer", - "tamasfe.even-better-toml", - "serayuzgur.crates" - ], - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "rustc --version", - - // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. - "remoteUser": "vscode" -} diff --git a/day3/rust/Cargo.toml b/day3/rust/Cargo.toml deleted file mode 100644 index 1ec6963..0000000 --- a/day3/rust/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "rust" -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/day4/rust/Cargo.toml b/day4/rust/Cargo.toml deleted file mode 100644 index 1ec6963..0000000 --- a/day4/rust/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "rust" -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/day5/rust/Cargo.toml b/day5/rust/Cargo.toml deleted file mode 100644 index 76e308a..0000000 --- a/day5/rust/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "rust" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -itertools = "0.10" diff --git a/debug.log b/debug.log deleted file mode 100644 index bea6f90..0000000 --- a/debug.log +++ /dev/null @@ -1,2 +0,0 @@ -[1204/174854.538:ERROR:registration_protocol_win.cc(102)] CreateFile: The system cannot find the file specified. (0x2) -[1217/131743.085:ERROR:registration_protocol_win.cc(102)] CreateFile: The system cannot find the file specified. (0x2) diff --git a/day1/input.txt b/inputs/day1.txt similarity index 100% rename from day1/input.txt rename to inputs/day1.txt diff --git a/day2/input.txt b/inputs/day2.txt similarity index 100% rename from day2/input.txt rename to inputs/day2.txt diff --git a/day3/input.txt b/inputs/day3.txt similarity index 100% rename from day3/input.txt rename to inputs/day3.txt diff --git a/day4/input.txt b/inputs/day4.txt similarity index 100% rename from day4/input.txt rename to inputs/day4.txt diff --git a/day5/input.txt b/inputs/day5.txt similarity index 100% rename from day5/input.txt rename to inputs/day5.txt diff --git a/day1/rust/src/main.rs b/src/day1.rs similarity index 76% rename from day1/rust/src/main.rs rename to src/day1.rs index e175beb..dac7dbb 100644 --- a/day1/rust/src/main.rs +++ b/src/day1.rs @@ -1,7 +1,8 @@ use std::fs; -fn main() { - let input = fs::read_to_string("../input.txt").expect("Could not read file"); +pub fn run() { + println!("Day 1:"); + let input = fs::read_to_string("./inputs/day1.txt").expect("Could not read file"); let lines: Vec = input.lines().map(|s| s.parse().unwrap()).collect(); @@ -20,7 +21,7 @@ fn part1(lines: &Vec) { previous = current; } - println!("Increases: {}", increases); + println!("\tPart 1: {}", increases); } fn part2(lines: &Vec) { @@ -36,5 +37,5 @@ fn part2(lines: &Vec) { previous = current; } - println!("Increases: {}", increases); + println!("\tPart 2: {}", increases); } diff --git a/day2/rust/src/main.rs b/src/day2.rs similarity index 83% rename from day2/rust/src/main.rs rename to src/day2.rs index b201bc2..a38b0a2 100644 --- a/day2/rust/src/main.rs +++ b/src/day2.rs @@ -1,7 +1,8 @@ use std::fs; -fn main() { - let input = fs::read_to_string("../input.txt").expect("Could not read file"); +pub fn run() { + println!("Day 2:"); + let input = fs::read_to_string("./inputs/day2.txt").expect("Could not read file"); let commands: Vec<(&str, i32)> = input .lines() @@ -33,7 +34,7 @@ fn part1(commands: &Vec<(&str, i32)>) { position += change.0; depth += change.1; } - println!("Part 1: {}", position * depth); + println!("\tPart 1: {}", position * depth); } fn part2(commands: &Vec<(&str, i32)>) { @@ -53,5 +54,5 @@ fn part2(commands: &Vec<(&str, i32)>) { position += change.0; depth += aim * change.0; } - println!("Part 2: {}", position * depth); + println!("\tPart 2: {}", position * depth); } diff --git a/day3/rust/src/main.rs b/src/day3.rs similarity index 90% rename from day3/rust/src/main.rs rename to src/day3.rs index 04f380f..127cfaa 100644 --- a/day3/rust/src/main.rs +++ b/src/day3.rs @@ -1,7 +1,8 @@ use std::fs; -fn main() { - let input = fs::read_to_string("../input.txt").expect("Could not read file"); +pub fn run() { + println!("Day 3:"); + let input = fs::read_to_string("./inputs/day3.txt").expect("Could not read file"); let report: Vec<&str> = input.lines().collect(); let bit_count = report[0].len(); @@ -28,7 +29,7 @@ fn main() { epsilon += 1; } } - println!("Part 1: {}", gamma * epsilon); + println!("\tPart 1: {}", gamma * epsilon); } { @@ -79,6 +80,6 @@ fn main() { i32::from_str_radix(diagnostic[0], 2).unwrap() }; - println!("Part 2: {}", generator * scrubber); + println!("\tPart 2: {}", generator * scrubber); } } diff --git a/day4/rust/src/main.rs b/src/day4.rs similarity index 58% rename from day4/rust/src/main.rs rename to src/day4.rs index 9410ea0..faa4aef 100644 --- a/day4/rust/src/main.rs +++ b/src/day4.rs @@ -1,16 +1,17 @@ use std::fs; -fn main() { - let input = fs::read_to_string("../input.txt").expect("Could not read file"); +pub fn run() { + println!("Day 4:"); + let input = fs::read_to_string("./inputs/day4.txt").expect("Could not read file"); let numbers: Vec<&str> = input.split('\n').next().unwrap().split(',').collect(); for i in numbers.iter() { - println!("{}", i); + println!("\t{}", i); } let boards: Vec<&str> = input.split("\n\n").collect(); println!("{}", boards.len()); for i in boards.iter() { - println!("{:?}", i); + println!("\t{:?}", i); } } diff --git a/day5/rust/src/main.rs b/src/day5.rs similarity index 79% rename from day5/rust/src/main.rs rename to src/day5.rs index 9069041..213ab12 100644 --- a/day5/rust/src/main.rs +++ b/src/day5.rs @@ -2,8 +2,9 @@ use itertools::Itertools; use std::collections::HashMap; use std::fs; -fn main() { - let input = fs::read_to_string("../input.txt").expect("Could not read file"); +pub fn run() { + println!("Day 5:"); + let input = fs::read_to_string("./inputs/day5.txt").expect("Could not read file"); let lines = input .lines() @@ -29,6 +30,6 @@ fn main() { } for (key, value) in points.into_iter() { - println!("({}, {}), {}", key.0, key.1, value); + println!("\t({}, {}), {}", key.0, key.1, value); } } diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0843088 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,14 @@ +mod day1; +mod day2; +mod day3; +mod day4; +mod day5; + +fn main() { + println!("Running Advent of Code 2021"); + day1::run(); + day2::run(); + day3::run(); + day4::run(); + day5::run(); +}