diff --git a/rustfmt.toml b/rustfmt.toml index 2a35f023..d6b90a31 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,2 @@ +style_edition = "2024" use_small_heuristics = "Max" diff --git a/src/year2016/day05.rs b/src/year2016/day05.rs index 2273f46f..03798330 100644 --- a/src/year2016/day05.rs +++ b/src/year2016/day05.rs @@ -6,8 +6,8 @@ //! [`Year 2015 Day 4`]: crate::year2015::day04 use crate::util::md5::*; use crate::util::thread::*; -use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; use std::sync::Mutex; +use std::sync::atomic::{AtomicBool, AtomicU32, Ordering}; struct Shared { prefix: String, diff --git a/src/year2016/day07.rs b/src/year2016/day07.rs index 94b0d61c..3b6bc6bc 100644 --- a/src/year2016/day07.rs +++ b/src/year2016/day07.rs @@ -38,11 +38,7 @@ pub fn part1(input: &[u8]) -> usize { } } - if positive && !negative { - count + 1 - } else { - count - } + if positive && !negative { count + 1 } else { count } } pub fn part2(input: &[u8]) -> usize { @@ -84,9 +80,5 @@ pub fn part2(input: &[u8]) -> usize { } } - if positive { - count + 1 - } else { - count - } + if positive { count + 1 } else { count } } diff --git a/src/year2016/day14.rs b/src/year2016/day14.rs index 7dbe9f69..55e4f40d 100644 --- a/src/year2016/day14.rs +++ b/src/year2016/day14.rs @@ -5,8 +5,8 @@ use crate::util::md5::*; use crate::util::thread::*; use std::collections::{BTreeMap, BTreeSet}; -use std::sync::atomic::{AtomicBool, AtomicI32, Ordering}; use std::sync::Mutex; +use std::sync::atomic::{AtomicBool, AtomicI32, Ordering}; /// Atomics can be safely shared between threads. struct Shared<'a> { diff --git a/src/year2017/day14.rs b/src/year2017/day14.rs index 57560b17..6470c6a3 100644 --- a/src/year2017/day14.rs +++ b/src/year2017/day14.rs @@ -6,8 +6,8 @@ //! [`Day 10`]: crate::year2017::day10 //! [`Day 12`]: crate::year2017::day12 use crate::util::thread::*; -use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Mutex; +use std::sync::atomic::{AtomicUsize, Ordering}; /// Atomics can be safely shared between threads. pub struct Shared { diff --git a/src/year2017/day15.rs b/src/year2017/day15.rs index 2cb6aaed..2b75a85d 100644 --- a/src/year2017/day15.rs +++ b/src/year2017/day15.rs @@ -11,7 +11,7 @@ use crate::util::iter::*; use crate::util::math::*; use crate::util::parse::*; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; -use std::sync::mpsc::{channel, Receiver, Sender}; +use std::sync::mpsc::{Receiver, Sender, channel}; use std::thread; const PART_ONE: usize = 40_000_000; diff --git a/src/year2018/day14.rs b/src/year2018/day14.rs index 7b601448..846fadc4 100644 --- a/src/year2018/day14.rs +++ b/src/year2018/day14.rs @@ -12,7 +12,7 @@ //! * Vector processing of recipes using techniques similar to SIMD. use crate::util::parse::*; use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::mpsc::{channel, Receiver, Sender}; +use std::sync::mpsc::{Receiver, Sender, channel}; use std::thread; type Input = (String, usize); diff --git a/src/year2018/day15.rs b/src/year2018/day15.rs index 57b852a5..83301eea 100644 --- a/src/year2018/day15.rs +++ b/src/year2018/day15.rs @@ -80,7 +80,7 @@ use crate::util::grid::*; use crate::util::point::*; use crate::util::thread::*; use std::sync::atomic::{AtomicBool, AtomicI32, Ordering}; -use std::sync::mpsc::{channel, Sender}; +use std::sync::mpsc::{Sender, channel}; const READING_ORDER: [Point; 4] = [UP, LEFT, RIGHT, DOWN]; diff --git a/src/year2018/day19.rs b/src/year2018/day19.rs index 26987093..d2681102 100644 --- a/src/year2018/day19.rs +++ b/src/year2018/day19.rs @@ -114,9 +114,5 @@ fn divisor_sum(mut n: u32) -> u32 { // If `n` is one then the greatest prime factor was repeated so has already been included in // the sum and we can just return it directly. Otherwise `n` is the unique greatest prime // factor and must be added to the sum. - if n == 1 { - sum - } else { - sum * (1 + n) - } + if n == 1 { sum } else { sum * (1 + n) } } diff --git a/src/year2018/day24.rs b/src/year2018/day24.rs index b5afab25..59a10142 100644 --- a/src/year2018/day24.rs +++ b/src/year2018/day24.rs @@ -11,7 +11,7 @@ use crate::util::hash::*; use crate::util::parse::*; use crate::util::thread::*; use std::sync::atomic::{AtomicBool, AtomicI32, Ordering}; -use std::sync::mpsc::{channel, Sender}; +use std::sync::mpsc::{Sender, channel}; pub struct Input { immune: Vec, diff --git a/src/year2019/day06.rs b/src/year2019/day06.rs index ac1bf30d..d4139f19 100644 --- a/src/year2019/day06.rs +++ b/src/year2019/day06.rs @@ -13,11 +13,7 @@ pub fn parse(input: &str) -> Vec { // Convert 'A'.."Z" and '0'..'9' to a number between 0 and 36. let digit = |b: u8| { - if b.is_ascii_digit() { - (b - b'0') as usize - } else { - (10 + b - b'A') as usize - } + if b.is_ascii_digit() { (b - b'0') as usize } else { (10 + b - b'A') as usize } }; // Hash each 3 character object name. diff --git a/src/year2019/day12.rs b/src/year2019/day12.rs index 6ed7ae70..4eab559b 100644 --- a/src/year2019/day12.rs +++ b/src/year2019/day12.rs @@ -23,11 +23,9 @@ type Input = [Axis; 3]; /// Group each axis together pub fn parse(input: &str) -> Input { let n: Vec<_> = input.iter_signed().collect(); - [ - [n[0], n[3], n[6], n[9], 0, 0, 0, 0], - [n[1], n[4], n[7], n[10], 0, 0, 0, 0], - [n[2], n[5], n[8], n[11], 0, 0, 0, 0], - ] + [[n[0], n[3], n[6], n[9], 0, 0, 0, 0], [n[1], n[4], n[7], n[10], 0, 0, 0, 0], [ + n[2], n[5], n[8], n[11], 0, 0, 0, 0, + ]] } pub fn part1(input: &Input) -> i32 { diff --git a/src/year2019/day25.rs b/src/year2019/day25.rs index 478f40af..37e9664f 100644 --- a/src/year2019/day25.rs +++ b/src/year2019/day25.rs @@ -26,11 +26,7 @@ pub fn parse(input: &str) -> Vec { } pub fn part1(input: &[i64]) -> String { - if cfg!(feature = "frivolity") { - play_manually(input) - } else { - play_automatically(input) - } + if cfg!(feature = "frivolity") { play_manually(input) } else { play_automatically(input) } } pub fn part2(_input: &[i64]) -> &'static str { diff --git a/src/year2020/day22.rs b/src/year2020/day22.rs index a8760e69..30ee1952 100644 --- a/src/year2020/day22.rs +++ b/src/year2020/day22.rs @@ -151,11 +151,7 @@ pub fn part1(input: &Input) -> usize { } } - if deck1.non_empty() { - deck1.score - } else { - deck2.score - } + if deck1.non_empty() { deck1.score } else { deck2.score } } pub fn part2(input: &Input) -> usize { @@ -210,9 +206,5 @@ fn combat(deck1: &mut Deck, deck2: &mut Deck, cache: &mut Cache, depth: usize) - } } - if deck1.non_empty() { - Winner::Player1 - } else { - Winner::Player2 - } + if deck1.non_empty() { Winner::Player1 } else { Winner::Player2 } } diff --git a/src/year2021/day07.rs b/src/year2021/day07.rs index 6ba7f132..452e3df7 100644 --- a/src/year2021/day07.rs +++ b/src/year2021/day07.rs @@ -37,11 +37,7 @@ fn median(input: &[i32]) -> i32 { let half = input.len() / 2; let odd = crabs.len() % 2 == 1; - if odd { - crabs[half] - } else { - (crabs[half - 1] + crabs[half]) / 2 - } + if odd { crabs[half] } else { (crabs[half - 1] + crabs[half]) / 2 } } fn mean(input: &[i32]) -> i32 { diff --git a/src/year2021/day13.rs b/src/year2021/day13.rs index 8a3314e7..877284f7 100644 --- a/src/year2021/day13.rs +++ b/src/year2021/day13.rs @@ -100,19 +100,11 @@ pub fn part2(input: &Input) -> String { /// Fold point at `x` coordinate, doing nothing if the point is to the left of the fold line. #[inline] fn fold_horizontal(x: i32, p: Point) -> Point { - if p.x < x { - p - } else { - Point::new(2 * x - p.x, p.y) - } + if p.x < x { p } else { Point::new(2 * x - p.x, p.y) } } /// Fold point at `y` coordinate, doing nothing if the point is above the fold line. #[inline] fn fold_vertical(y: i32, p: Point) -> Point { - if p.y < y { - p - } else { - Point::new(p.x, 2 * y - p.y) - } + if p.y < y { p } else { Point::new(p.x, 2 * y - p.y) } } diff --git a/src/year2021/day16.rs b/src/year2021/day16.rs index 3bbfbaee..a9322c05 100644 --- a/src/year2021/day16.rs +++ b/src/year2021/day16.rs @@ -42,11 +42,7 @@ impl BitStream<'_> { fn hex_to_binary(&mut self) -> u64 { let hex_digit = self.iter.next().unwrap(); - if hex_digit.is_ascii_digit() { - (hex_digit - 48) as u64 - } else { - (hex_digit - 55) as u64 - } + if hex_digit.is_ascii_digit() { (hex_digit - 48) as u64 } else { (hex_digit - 55) as u64 } } } diff --git a/src/year2022/day10.rs b/src/year2022/day10.rs index dd36023f..ef410056 100644 --- a/src/year2022/day10.rs +++ b/src/year2022/day10.rs @@ -27,11 +27,7 @@ pub fn part1(input: &[i32]) -> i32 { /// Returns pixels as a multi-line [`String`] so that the entire function can be integration tested. pub fn part2(input: &[i32]) -> String { let to_char = |(i, c): (usize, &i32)| { - if ((i as i32) - c).abs() <= 1 { - '#' - } else { - '.' - } + if ((i as i32) - c).abs() <= 1 { '#' } else { '.' } }; let mut result = input .chunks_exact(40) diff --git a/src/year2022/day13.rs b/src/year2022/day13.rs index 36ac26f5..1f2624e1 100644 --- a/src/year2022/day13.rs +++ b/src/year2022/day13.rs @@ -41,11 +41,7 @@ pub fn part1(input: &[&str]) -> usize { .enumerate() .map(|(i, chunk)| { let ordered = compare(chunk[0], chunk[1]); - if ordered { - i + 1 - } else { - 0 - } + if ordered { i + 1 } else { 0 } }) .sum() } diff --git a/src/year2023/day16.rs b/src/year2023/day16.rs index 96d6798d..a777286b 100644 --- a/src/year2023/day16.rs +++ b/src/year2023/day16.rs @@ -15,8 +15,8 @@ use crate::util::grid::*; use crate::util::point::*; use crate::util::thread::*; use std::collections::VecDeque; -use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Mutex; +use std::sync::atomic::{AtomicUsize, Ordering}; type Pair = (Point, u32); diff --git a/src/year2024/day02.rs b/src/year2024/day02.rs index 0f6cd41a..9a254b3d 100644 --- a/src/year2024/day02.rs +++ b/src/year2024/day02.rs @@ -77,9 +77,5 @@ fn check(report: &[i32]) -> (u32, u32) { fn delta(a: i32, b: i32) -> i32 { let diff = b - a; - if diff.abs() <= 3 { - diff.signum() - } else { - 0 - } + if diff.abs() <= 3 { diff.signum() } else { 0 } } diff --git a/src/year2024/day13.rs b/src/year2024/day13.rs index a423817c..fad7e348 100644 --- a/src/year2024/day13.rs +++ b/src/year2024/day13.rs @@ -56,9 +56,5 @@ fn play(&[ax, ay, bx, by, mut px, mut py]: &Claw, part_two: bool) -> i64 { a /= det; b /= det; - if part_two || (a <= 100 && b <= 100) { - 3 * a + b - } else { - 0 - } + if part_two || (a <= 100 && b <= 100) { 3 * a + b } else { 0 } }