Skip to content

Commit

Permalink
Rust 2024 Edition formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
maneatingape committed Jan 1, 2025
1 parent 59828aa commit 235f240
Show file tree
Hide file tree
Showing 22 changed files with 27 additions and 88 deletions.
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
style_edition = "2024"
use_small_heuristics = "Max"
2 changes: 1 addition & 1 deletion src/year2016/day05.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 2 additions & 10 deletions src/year2016/day07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -84,9 +80,5 @@ pub fn part2(input: &[u8]) -> usize {
}
}

if positive {
count + 1
} else {
count
}
if positive { count + 1 } else { count }
}
2 changes: 1 addition & 1 deletion src/year2016/day14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/year2017/day14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/year2017/day15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/year2018/day14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/year2018/day15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
6 changes: 1 addition & 5 deletions src/year2018/day19.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
2 changes: 1 addition & 1 deletion src/year2018/day24.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Group>,
Expand Down
6 changes: 1 addition & 5 deletions src/year2019/day06.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
pub fn parse(input: &str) -> Vec<usize> {
// 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.
Expand Down
8 changes: 3 additions & 5 deletions src/year2019/day12.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 1 addition & 5 deletions src/year2019/day25.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ pub fn parse(input: &str) -> Vec<i64> {
}

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 {
Expand Down
12 changes: 2 additions & 10 deletions src/year2020/day22.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
}
6 changes: 1 addition & 5 deletions src/year2021/day07.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 2 additions & 10 deletions src/year2021/day13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
6 changes: 1 addition & 5 deletions src/year2021/day16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/year2022/day10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions src/year2022/day13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion src/year2023/day16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 1 addition & 5 deletions src/year2024/day02.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
6 changes: 1 addition & 5 deletions src/year2024/day13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

0 comments on commit 235f240

Please sign in to comment.