From e2b338fc31c8b30ada08a44add14c0f340a10ddc Mon Sep 17 00:00:00 2001 From: mirsella Date: Fri, 6 Dec 2024 12:47:07 +0100 Subject: [PATCH] 2024: improve cargo workspace --- 2024/Cargo.toml | 35 ++++++++--------------------------- 2024/day1/Cargo.toml | 3 +-- 2024/day1/build.rs | 28 ---------------------------- 2024/day2/Cargo.toml | 3 +-- 2024/day2/build.rs | 28 ---------------------------- 2024/day3/Cargo.toml | 5 ++--- 2024/day3/build.rs | 28 ---------------------------- 2024/day4/Cargo.toml | 5 ++--- 2024/day4/build.rs | 28 ---------------------------- 2024/day4/src/main.rs | 1 - 2024/day5/Cargo.toml | 3 +-- 2024/day5/build.rs | 28 ---------------------------- 2024/day6/Cargo.toml | 6 +++--- 2024/day6/build.rs | 28 ---------------------------- 2024/day6/src/main.rs | 1 + 15 files changed, 19 insertions(+), 211 deletions(-) delete mode 100644 2024/day1/build.rs delete mode 100644 2024/day2/build.rs delete mode 100644 2024/day3/build.rs delete mode 100644 2024/day4/build.rs delete mode 100644 2024/day5/build.rs delete mode 100644 2024/day6/build.rs diff --git a/2024/Cargo.toml b/2024/Cargo.toml index 9a65382..4da11e5 100644 --- a/2024/Cargo.toml +++ b/2024/Cargo.toml @@ -1,29 +1,10 @@ [workspace] resolver = "2" -members = [ - "day1", - "day2", - "day3", - "day4", - "day5", - "day6", - # "day7", - # "day8", - # "day9", - # "day10", - # "day11", - # "day12", - # "day13", - # "day14", - # "day15", - # "day16", - # "day17", - # "day18", - # "day19", - # "day20", - # "day21", - # "day22", - # "day23", - # "day24", - # "day25", -] +members = ["day*"] + +[workspace.dependencies] +itertools = "0.13.0" +pathfinding = "4.11.0" +rayon = "1.10.0" +regex = "1.10.2" +indexmap = { version = "2.7.0", features = ["rayon"] } diff --git a/2024/day1/Cargo.toml b/2024/day1/Cargo.toml index 0007567..158964b 100644 --- a/2024/day1/Cargo.toml +++ b/2024/day1/Cargo.toml @@ -7,5 +7,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -itertools = "0.13.0" - +itertools = { workspace = true } diff --git a/2024/day1/build.rs b/2024/day1/build.rs deleted file mode 100644 index b6a19a0..0000000 --- a/2024/day1/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::fs::File; -use std::io::{self, Read}; -use std::path::PathBuf; -use std::{env, fs}; - -fn replace_in_file(file_path: &PathBuf, old: &str, new: &str) -> io::Result<()> { - let mut contents = String::new(); - File::open(file_path)?.read_to_string(&mut contents)?; - let new_contents = contents.replace(old, new); - if contents != new_contents { - println!("Updating {}", file_path.display()); - fs::write(file_path, new_contents)?; - } - Ok(()) -} - -fn main() -> io::Result<()> { - let pkg_name = env::var("CARGO_PKG_NAME").unwrap(); - replace_in_file( - &"../Cargo.toml".into(), - &format!("# \"{pkg_name}\""), - &format!("\"{pkg_name}\""), - )?; - - replace_in_file(&"./Cargo.toml".into(), "\n[workspace]", "")?; - - Ok(()) -} diff --git a/2024/day2/Cargo.toml b/2024/day2/Cargo.toml index b883b45..8c48c48 100644 --- a/2024/day2/Cargo.toml +++ b/2024/day2/Cargo.toml @@ -7,5 +7,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -itertools = "0.13.0" - +itertools = { workspace = true } diff --git a/2024/day2/build.rs b/2024/day2/build.rs deleted file mode 100644 index b6a19a0..0000000 --- a/2024/day2/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::fs::File; -use std::io::{self, Read}; -use std::path::PathBuf; -use std::{env, fs}; - -fn replace_in_file(file_path: &PathBuf, old: &str, new: &str) -> io::Result<()> { - let mut contents = String::new(); - File::open(file_path)?.read_to_string(&mut contents)?; - let new_contents = contents.replace(old, new); - if contents != new_contents { - println!("Updating {}", file_path.display()); - fs::write(file_path, new_contents)?; - } - Ok(()) -} - -fn main() -> io::Result<()> { - let pkg_name = env::var("CARGO_PKG_NAME").unwrap(); - replace_in_file( - &"../Cargo.toml".into(), - &format!("# \"{pkg_name}\""), - &format!("\"{pkg_name}\""), - )?; - - replace_in_file(&"./Cargo.toml".into(), "\n[workspace]", "")?; - - Ok(()) -} diff --git a/2024/day3/Cargo.toml b/2024/day3/Cargo.toml index 75e1a5a..197b212 100644 --- a/2024/day3/Cargo.toml +++ b/2024/day3/Cargo.toml @@ -7,6 +7,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -itertools = "0.13.0" -regex = "1.11.1" - +itertools = { workspace = true } +regex = { workspace = true } diff --git a/2024/day3/build.rs b/2024/day3/build.rs deleted file mode 100644 index b6a19a0..0000000 --- a/2024/day3/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::fs::File; -use std::io::{self, Read}; -use std::path::PathBuf; -use std::{env, fs}; - -fn replace_in_file(file_path: &PathBuf, old: &str, new: &str) -> io::Result<()> { - let mut contents = String::new(); - File::open(file_path)?.read_to_string(&mut contents)?; - let new_contents = contents.replace(old, new); - if contents != new_contents { - println!("Updating {}", file_path.display()); - fs::write(file_path, new_contents)?; - } - Ok(()) -} - -fn main() -> io::Result<()> { - let pkg_name = env::var("CARGO_PKG_NAME").unwrap(); - replace_in_file( - &"../Cargo.toml".into(), - &format!("# \"{pkg_name}\""), - &format!("\"{pkg_name}\""), - )?; - - replace_in_file(&"./Cargo.toml".into(), "\n[workspace]", "")?; - - Ok(()) -} diff --git a/2024/day4/Cargo.toml b/2024/day4/Cargo.toml index a4ff73b..de93f6b 100644 --- a/2024/day4/Cargo.toml +++ b/2024/day4/Cargo.toml @@ -7,6 +7,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -itertools = "0.13.0" -pathfinding = "4.11.0" - +itertools = { workspace = true } +pathfinding = { workspace = true } diff --git a/2024/day4/build.rs b/2024/day4/build.rs deleted file mode 100644 index b6a19a0..0000000 --- a/2024/day4/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::fs::File; -use std::io::{self, Read}; -use std::path::PathBuf; -use std::{env, fs}; - -fn replace_in_file(file_path: &PathBuf, old: &str, new: &str) -> io::Result<()> { - let mut contents = String::new(); - File::open(file_path)?.read_to_string(&mut contents)?; - let new_contents = contents.replace(old, new); - if contents != new_contents { - println!("Updating {}", file_path.display()); - fs::write(file_path, new_contents)?; - } - Ok(()) -} - -fn main() -> io::Result<()> { - let pkg_name = env::var("CARGO_PKG_NAME").unwrap(); - replace_in_file( - &"../Cargo.toml".into(), - &format!("# \"{pkg_name}\""), - &format!("\"{pkg_name}\""), - )?; - - replace_in_file(&"./Cargo.toml".into(), "\n[workspace]", "")?; - - Ok(()) -} diff --git a/2024/day4/src/main.rs b/2024/day4/src/main.rs index 15abbcb..00b8710 100644 --- a/2024/day4/src/main.rs +++ b/2024/day4/src/main.rs @@ -1,4 +1,3 @@ -use itertools::Itertools; use pathfinding::matrix::{directions::*, Matrix}; use std::collections::HashSet; use std::iter; diff --git a/2024/day5/Cargo.toml b/2024/day5/Cargo.toml index 20cbf96..f525f65 100644 --- a/2024/day5/Cargo.toml +++ b/2024/day5/Cargo.toml @@ -7,5 +7,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -itertools = "0.13.0" - +itertools = { workspace = true } diff --git a/2024/day5/build.rs b/2024/day5/build.rs deleted file mode 100644 index b6a19a0..0000000 --- a/2024/day5/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::fs::File; -use std::io::{self, Read}; -use std::path::PathBuf; -use std::{env, fs}; - -fn replace_in_file(file_path: &PathBuf, old: &str, new: &str) -> io::Result<()> { - let mut contents = String::new(); - File::open(file_path)?.read_to_string(&mut contents)?; - let new_contents = contents.replace(old, new); - if contents != new_contents { - println!("Updating {}", file_path.display()); - fs::write(file_path, new_contents)?; - } - Ok(()) -} - -fn main() -> io::Result<()> { - let pkg_name = env::var("CARGO_PKG_NAME").unwrap(); - replace_in_file( - &"../Cargo.toml".into(), - &format!("# \"{pkg_name}\""), - &format!("\"{pkg_name}\""), - )?; - - replace_in_file(&"./Cargo.toml".into(), "\n[workspace]", "")?; - - Ok(()) -} diff --git a/2024/day6/Cargo.toml b/2024/day6/Cargo.toml index fc33b2c..d066da5 100644 --- a/2024/day6/Cargo.toml +++ b/2024/day6/Cargo.toml @@ -7,6 +7,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -itertools = "0.13.0" -pathfinding = "4.11.0" -rayon = "1.10.0" +itertools = { workspace = true } +pathfinding = { workspace = true } +rayon = { workspace = true } diff --git a/2024/day6/build.rs b/2024/day6/build.rs deleted file mode 100644 index b6a19a0..0000000 --- a/2024/day6/build.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::fs::File; -use std::io::{self, Read}; -use std::path::PathBuf; -use std::{env, fs}; - -fn replace_in_file(file_path: &PathBuf, old: &str, new: &str) -> io::Result<()> { - let mut contents = String::new(); - File::open(file_path)?.read_to_string(&mut contents)?; - let new_contents = contents.replace(old, new); - if contents != new_contents { - println!("Updating {}", file_path.display()); - fs::write(file_path, new_contents)?; - } - Ok(()) -} - -fn main() -> io::Result<()> { - let pkg_name = env::var("CARGO_PKG_NAME").unwrap(); - replace_in_file( - &"../Cargo.toml".into(), - &format!("# \"{pkg_name}\""), - &format!("\"{pkg_name}\""), - )?; - - replace_in_file(&"./Cargo.toml".into(), "\n[workspace]", "")?; - - Ok(()) -} diff --git a/2024/day6/src/main.rs b/2024/day6/src/main.rs index 5ddea84..47fcc6a 100644 --- a/2024/day6/src/main.rs +++ b/2024/day6/src/main.rs @@ -74,6 +74,7 @@ fn part2_clever(input: &str) -> usize { } // bruteforce but thanks to rayon its still really fast +// it can be much simpler, but i wanted to be able to visually debug the matrix if needed, so i modify the code directly fn part2(input: &str) -> usize { let directions = [(N, '^'), (E, '>'), (S, 'v'), (W, '<')]; let get_direction = |char: char| directions.iter().find(|(_, c)| char == *c).unwrap().0;