diff --git a/CHANGELOG.md b/CHANGELOG.md index a0ea4e6..a418dd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ Of note: - The changelog 2015.5.2 has been rewritten from each commit content. - This file may be amended entirely in the future to adhere to the [GNU Changelog style](https://www.gnu.org/prep/standards/html_node/Style-of-Change-Logs.html#Style-of-Change-Logs) +## [2018.6.2] +### Changed +- Updated dependencies, changed all `ToString` implementations to `fmt::Display`, and other clippy improvements + ## [2018.6.1] ### Added - Solved [exercice for 2018, day 06](src/year_2018/06.rs). diff --git a/Cargo.toml b/Cargo.toml index 589cd38..a5e4160 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,12 @@ +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + [package] name = "advent-rs" -version = "2018.6.1" +version = "2018.6.2" edition = "2021" authors = ["Arnaud 'red' Rouyer"] readme = "README.md" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [[bin]] name = "advent-rs" path = "src/main.rs" @@ -26,17 +26,21 @@ opt-level = 2 [profile.release] opt-level = 3 +strip = true # Strip symbols +panic = "abort" # Abort on panic +# lto = true # Enable Link Time Optimization +# codegen-units = 1 # Reduce number of codegen units to increase optimizations. [dependencies] -clap = { version = "4.5.1", features = ["derive"] } -itertools = "0.12.1" +clap = { version = "4.5.20", features = ["derive"] } +itertools = "0.13.0" md-5 = "0.10.6" -mutants = "0.0.3" [dev-dependencies] -assert_cmd = "2.0.13" -predicates = "3.1.0" +assert_cmd = "2.0.16" +predicates = "3.1.2" criterion = { version = "0.5.1", features = ["html_reports"] } +mutants = "0.0.3" [[bench]] name = "year_2015" diff --git a/benches/year_2017_day_04.rs b/benches/year_2017_day_04.rs index 2f7d55b..c0d0d9b 100644 --- a/benches/year_2017_day_04.rs +++ b/benches/year_2017_day_04.rs @@ -11,7 +11,7 @@ pub fn day_04_v1_naive(input: impl Into) -> u16 { line .split_whitespace() .sorted() - .group_by(|word| *word) + .chunk_by(|word| *word) .into_iter() .all(|(_word, group)| group.count() == 1) }) diff --git a/src/year_2015/day_04.rs b/src/year_2015/day_04.rs index d6f5460..7fb3df1 100644 --- a/src/year_2015/day_04.rs +++ b/src/year_2015/day_04.rs @@ -53,7 +53,7 @@ fn find_hash(input: &str, stop_value: u8) -> u32 { (0..=u32::MAX) .find(|counter| { let mut hasher = md5.clone(); - hasher.update(&counter.to_string()); + hasher.update(counter.to_string()); let hash = hasher.finalize(); hash[0] == 0 && hash[1] == 0 && hash[2] < stop_value }) diff --git a/src/year_2015/day_18.rs b/src/year_2015/day_18.rs index 1c91874..e71db4c 100644 --- a/src/year_2015/day_18.rs +++ b/src/year_2015/day_18.rs @@ -1,4 +1,5 @@ //! Advent of Code 2015: Day 18: Like a GIF For Your Yard +use std::fmt; type Light = bool; const LIGHT_ON: Light = true; @@ -127,20 +128,18 @@ impl GameOfLifeGrid { } } -impl ToString for GameOfLifeGrid { - fn to_string(&self) -> String { - let mut data: String = String::new(); +impl fmt::Display for GameOfLifeGrid { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for row in 0..self.size { - let row_str = self.data[row] - .iter() - .map(|c| if *c == LIGHT_ON { "#" } else { "." }) - .collect::>() - .join(""); - data.push_str(&row_str); - data.push('\n'); + for col in 0..self.size { + match self.data[row][col] { + LIGHT_ON => write!(f, "#")?, + LIGHT_OFF => write!(f, ".")?, + } + } + writeln!(f)?; } - - data + Ok(()) } } diff --git a/src/year_2016/day_06.rs b/src/year_2016/day_06.rs index 3a8ea86..c62768b 100644 --- a/src/year_2016/day_06.rs +++ b/src/year_2016/day_06.rs @@ -21,7 +21,7 @@ where let (next_char, _) = row .iter() .sorted() - .group_by(|&x| x) + .chunk_by(|&x| x) .into_iter() .map(|(key, group)| (key, group.count())) .max_by(&sort_closure) diff --git a/src/year_2016/day_14.rs b/src/year_2016/day_14.rs index 93279b6..31d1177 100644 --- a/src/year_2016/day_14.rs +++ b/src/year_2016/day_14.rs @@ -18,7 +18,7 @@ fn fill_hashes_v2(md5: &CoreWrapper, start: usize, end: usize) -> VecDe let mut hashes: VecDeque = VecDeque::new(); for idx in start..=end { let mut md5_num = md5.clone(); - md5_num.update(&idx.to_string()); + md5_num.update(idx.to_string()); let md5_str = Md5::new(); hashes.push_back(multi_hash(&md5_str, &format!("{:x}", md5_num.finalize()))); } @@ -86,7 +86,7 @@ fn fill_hashes(md5: &CoreWrapper, counter: usize, hashes: usize) -> Vec let mut hashes: VecDeque> = VecDeque::new(); for idx in start..=end { let mut md5_num = md5.clone(); - md5_num.update(&idx.to_string()); + md5_num.update(idx.to_string()); hashes.push_back(md5_num.finalize().to_vec()); } diff --git a/src/year_2017/day_07.rs b/src/year_2017/day_07.rs index b85b357..a041ddc 100644 --- a/src/year_2017/day_07.rs +++ b/src/year_2017/day_07.rs @@ -118,7 +118,7 @@ pub fn day_07_v2(input: impl Into) -> String { .iter() .map(|n| tower.size_of(n)) .sorted() - .group_by(|v| *v) + .chunk_by(|v| *v) .into_iter() .map(|(key, group)| (key, group.count())) .sorted_by_key(|elt| elt.1) diff --git a/src/year_2017/day_16.rs b/src/year_2017/day_16.rs index cc167e7..3082796 100644 --- a/src/year_2017/day_16.rs +++ b/src/year_2017/day_16.rs @@ -59,9 +59,10 @@ impl DanceFloor { } } -impl ToString for DanceFloor { - fn to_string(&self) -> String { - self.input.iter().collect::() +impl std::fmt::Display for DanceFloor { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let string = self.input.iter().collect::(); + write!(f, "{}", string) } } diff --git a/src/year_2017/day_21.rs b/src/year_2017/day_21.rs index a2c31d6..21b3aa2 100644 --- a/src/year_2017/day_21.rs +++ b/src/year_2017/day_21.rs @@ -1,5 +1,6 @@ use itertools::Itertools; use std::collections::HashMap; +use std::fmt; use std::hash::Hash; #[derive(Clone, Eq, Hash, PartialEq)] @@ -114,14 +115,18 @@ impl Default for Pattern { } } -impl ToString for Pattern { - fn to_string(&self) -> String { - self - .data - .iter() - .map(|row| row.iter().map(|chr| if *chr { "#" } else { "." }).join("")) - .join("\n") - .to_string() +impl fmt::Display for Pattern { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + for row in self.data.iter() { + for chr in row.iter() { + match chr { + true => write!(f, "#")?, + false => write!(f, ".")?, + } + } + writeln!(f)? + } + Ok(()) } } diff --git a/src/year_2017/day_25.rs b/src/year_2017/day_25.rs index d3527c1..f4d95ff 100644 --- a/src/year_2017/day_25.rs +++ b/src/year_2017/day_25.rs @@ -1,3 +1,4 @@ +use core::fmt; use std::collections::HashMap; use itertools::Itertools; @@ -121,14 +122,15 @@ impl StateMachine { } } -impl ToString for StateMachine { - fn to_string(&self) -> String { - self - .tape - .iter() - .sorted() - .map(|(_idx, value)| if *value { "1" } else { "0" }) - .join(" ") +impl fmt::Display for StateMachine { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + for (_idx, value) in self.tape.iter().sorted() { + match value { + true => write!(f, "1 ")?, + false => write!(f, "0 ")?, + } + } + Ok(()) } } diff --git a/src/year_2018/day_02.rs b/src/year_2018/day_02.rs index 7975760..72c33ba 100644 --- a/src/year_2018/day_02.rs +++ b/src/year_2018/day_02.rs @@ -7,7 +7,7 @@ pub fn day_02_v1(input: impl Into) -> String { .map(|input| { let mut two = false; let mut tre = false; - for (_chr, cnt) in &input.bytes().sorted().group_by(|chr| *chr) { + for (_chr, cnt) in &input.bytes().sorted().chunk_by(|chr| *chr) { match cnt.count() { 2 => two = true, 3 => tre = true, diff --git a/src/year_2018/day_06.rs b/src/year_2018/day_06.rs index 01176d9..1626078 100644 --- a/src/year_2018/day_06.rs +++ b/src/year_2018/day_06.rs @@ -16,10 +16,10 @@ struct ChronalCoordinates { impl ChronalCoordinates { fn new(input: &str) -> Self { - let mut left = std::i32::MAX; - let mut top = std::i32::MAX; - let mut right = std::i32::MIN; - let mut bottom = std::i32::MIN; + let mut left = i32::MAX; + let mut top = i32::MAX; + let mut right = i32::MIN; + let mut bottom = i32::MIN; let points = input .lines() @@ -54,7 +54,7 @@ impl ChronalCoordinates { for x in self.left..=self.right { for y in self.top..=self.bottom { - let mut closest_distance = std::i32::MAX; + let mut closest_distance = i32::MAX; let mut closest_id = 0; for (id, point) in self.points.iter() {