From b4c1f36767a62017029ec448581aa0b0b9a3080a Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 15 Nov 2019 00:14:07 +0100 Subject: [PATCH] move everything to single crate --- 2018/aoc02/Cargo.toml | 9 ------ Cargo.lock | 6 +--- Cargo.toml | 3 +- {2018/aoc01 => aoc2018}/Cargo.toml | 2 +- .../input.txt => aoc2018/input/day01.txt | 0 .../input.txt => aoc2018/input/day02.txt | 0 .../aoc01/src/main.rs => aoc2018/src/day01.rs | 28 +++++-------------- .../aoc02/src/main.rs => aoc2018/src/day02.rs | 21 ++++---------- aoc2018/src/lib.rs | 4 +++ aoc2018/src/main.rs | 19 +++++++++++++ 10 files changed, 38 insertions(+), 54 deletions(-) delete mode 100644 2018/aoc02/Cargo.toml rename {2018/aoc01 => aoc2018}/Cargo.toml (92%) rename 2018/aoc01/input/input.txt => aoc2018/input/day01.txt (100%) rename 2018/aoc02/input/input.txt => aoc2018/input/day02.txt (100%) rename 2018/aoc01/src/main.rs => aoc2018/src/day01.rs (73%) rename 2018/aoc02/src/main.rs => aoc2018/src/day02.rs (61%) create mode 100644 aoc2018/src/lib.rs create mode 100644 aoc2018/src/main.rs diff --git a/2018/aoc02/Cargo.toml b/2018/aoc02/Cargo.toml deleted file mode 100644 index 58c8f72..0000000 --- a/2018/aoc02/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "aoc02" -version = "0.1.0" -authors = ["Antoine Martin "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/Cargo.lock b/Cargo.lock index 5fc2e56..49c24ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,10 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "aoc01" -version = "0.1.0" - -[[package]] -name = "aoc02" +name = "aoc2018" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 91cf50d..2e6289c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,4 @@ [workspace] members = [ - "2018/aoc01", - "2018/aoc02", + "aoc2018", ] diff --git a/2018/aoc01/Cargo.toml b/aoc2018/Cargo.toml similarity index 92% rename from 2018/aoc01/Cargo.toml rename to aoc2018/Cargo.toml index 46d11a5..5ebb51f 100644 --- a/2018/aoc01/Cargo.toml +++ b/aoc2018/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "aoc01" +name = "aoc2018" version = "0.1.0" authors = ["Antoine Martin "] edition = "2018" diff --git a/2018/aoc01/input/input.txt b/aoc2018/input/day01.txt similarity index 100% rename from 2018/aoc01/input/input.txt rename to aoc2018/input/day01.txt diff --git a/2018/aoc02/input/input.txt b/aoc2018/input/day02.txt similarity index 100% rename from 2018/aoc02/input/input.txt rename to aoc2018/input/day02.txt diff --git a/2018/aoc01/src/main.rs b/aoc2018/src/day01.rs similarity index 73% rename from 2018/aoc01/src/main.rs rename to aoc2018/src/day01.rs index 7bfbf91..8695bff 100644 --- a/2018/aoc01/src/main.rs +++ b/aoc2018/src/day01.rs @@ -1,21 +1,12 @@ use std::collections::HashSet; -use std::env; -use std::fs; -type Result = std::result::Result>; +use super::Result; -fn main() -> Result<()> { - let mut args = env::args(); - args.next(); +const INPUT: &str = include_str!("../input/day01.txt"); - let input = fs::read_to_string( - &args - .next() - .expect("Please provide the path to the input file"), - )?; - - println!("part 1: {}", part1(&input)?); - println!("part 2: {}", part2(&input)?); +pub fn run() -> Result<()> { + println!("part 1: {}", part1(INPUT)?); + println!("part 2: {}", part2(INPUT)?); Ok(()) } @@ -34,7 +25,6 @@ fn part2(input: &str) -> Result { loop { for line in input.lines() { if freqs.contains(&freq) { - println!("{}", freq); return Ok(freq); } else { freqs.insert(freq); @@ -91,9 +81,7 @@ mod tests { #[test] fn part1_real() { - let input = include_str!("../input/input.txt"); - - assert_eq!(part1(input).unwrap(), 427); + assert_eq!(part1(INPUT).unwrap(), 427); } #[test] @@ -154,8 +142,6 @@ mod tests { #[test] fn part2_real() { - let input = include_str!("../input/input.txt"); - - assert_eq!(part2(input).unwrap(), 341); + assert_eq!(part2(INPUT).unwrap(), 341); } } diff --git a/2018/aoc02/src/main.rs b/aoc2018/src/day02.rs similarity index 61% rename from 2018/aoc02/src/main.rs rename to aoc2018/src/day02.rs index 92e565f..e347c5f 100644 --- a/2018/aoc02/src/main.rs +++ b/aoc2018/src/day02.rs @@ -1,20 +1,11 @@ use std::collections::HashMap; -use std::env; -use std::fs; -type Result = std::result::Result>; +use super::Result; -fn main() -> Result<()> { - let mut args = env::args(); - args.next(); +const INPUT: &str = include_str!("../input/day02.txt"); - let input = fs::read_to_string( - &args - .next() - .expect("Please provide the path to the input file"), - )?; - - println!("part 1: {}", part1(&input)?); +pub fn run() -> Result<()> { + println!("part 1: {}", part1(INPUT)?); Ok(()) } @@ -61,8 +52,6 @@ ababab #[test] fn part1_real() { - let input = include_str!("../input/input.txt"); - - assert_eq!(part1(input).unwrap(), 5750); + assert_eq!(part1(INPUT).unwrap(), 5750); } } diff --git a/aoc2018/src/lib.rs b/aoc2018/src/lib.rs new file mode 100644 index 0000000..464d775 --- /dev/null +++ b/aoc2018/src/lib.rs @@ -0,0 +1,4 @@ +pub mod day01; +pub mod day02; + +pub type Result = std::result::Result>; diff --git a/aoc2018/src/main.rs b/aoc2018/src/main.rs new file mode 100644 index 0000000..2ca3d8d --- /dev/null +++ b/aoc2018/src/main.rs @@ -0,0 +1,19 @@ +use std::env; + +use aoc2018::day01; +use aoc2018::day02; +use aoc2018::Result; + +fn main() -> Result<()> { + let days = [day01::run, day02::run]; + + let mut args = env::args(); + args.next(); + + let day = args + .next() + .expect("Please provide a day to launch") + .parse::()?; + + days[day - 1]() +}