Skip to content

Commit 01bd3b6

Browse files
committed
1 parent cd53504 commit 01bd3b6

File tree

12 files changed

+21
-16
lines changed

12 files changed

+21
-16
lines changed

crates/utils/src/date.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ impl Date {
1919
let mut days = u64::from(self.day.0) - 1;
2020

2121
for year in 2016..=self.year.0 {
22-
let is_leap_year = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
22+
let is_leap_year =
23+
(year.is_multiple_of(4) && !year.is_multiple_of(100)) || year.is_multiple_of(400);
2324
days += if is_leap_year { 366 } else { 365 };
2425
}
2526

crates/year2015/src/day23.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ impl Day23 {
6969
Instruction::Increment(Register::A) => a += 1,
7070
Instruction::Increment(Register::B) => b += 1,
7171
Instruction::Jump(offset) => pc += offset - 1,
72-
Instruction::JumpIfEven(Register::A, offset) if a % 2 == 0 => pc += offset - 1,
73-
Instruction::JumpIfEven(Register::B, offset) if b % 2 == 0 => pc += offset - 1,
72+
Instruction::JumpIfEven(Register::A, offset) if a.is_multiple_of(2) => {
73+
pc += offset - 1
74+
}
75+
Instruction::JumpIfEven(Register::B, offset) if b.is_multiple_of(2) => {
76+
pc += offset - 1
77+
}
7478
Instruction::JumpIfOne(Register::A, offset) if a == 1 => pc += offset - 1,
7579
Instruction::JumpIfOne(Register::B, offset) if b == 1 => pc += offset - 1,
7680
Instruction::JumpIfEven(_, _) | Instruction::JumpIfOne(_, _) => {}

crates/year2015/src/day24.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Day24 {
2626
remaining_totals.reverse();
2727

2828
let sum: u32 = remaining_totals.first().copied().unwrap_or(0);
29-
if sum % 12 != 0 {
29+
if !sum.is_multiple_of(12) {
3030
return Err(InputError::new(input, 0, "Total must be multiple of 12"));
3131
}
3232

crates/year2016/src/day13.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Day13 {
4444
Point2D::new(p.x, p.y.saturating_add(1)),
4545
] {
4646
let n = (x * x) + (3 * x) + (2 * x * y) + y + (y * y) + favorite_number;
47-
if n.count_ones() % 2 == 0 && !visited.contains(&next) {
47+
if n.count_ones().is_multiple_of(2) && !visited.contains(&next) {
4848
visited.insert(next);
4949
queue.push_back((next, steps + 1));
5050
}

crates/year2017/src/day02.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Day02 {
3434
.map(|row| {
3535
for i in 0..row.len() - 1 {
3636
for j in i + 1..row.len() {
37-
if row[j] % row[i] == 0 {
37+
if row[j].is_multiple_of(row[i]) {
3838
return row[j] / row[i];
3939
}
4040
}

crates/year2017/src/day13.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Day13 {
2727
.iter()
2828
.map(|&(depth, range)| {
2929
let period = (range - 1) * 2;
30-
if depth % period == 0 {
30+
if depth.is_multiple_of(period) {
3131
depth * range
3232
} else {
3333
0

crates/year2017/src/day15.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::BTreeMap;
2-
use std::sync::atomic::{AtomicU32, Ordering};
32
use std::sync::Mutex;
3+
use std::sync::atomic::{AtomicU32, Ordering};
44
use utils::multithreading;
55
use utils::number::mod_pow;
66
use utils::prelude::*;
@@ -112,10 +112,10 @@ impl Day15 {
112112
if a as u16 == b as u16 {
113113
part1_matches += 1;
114114
}
115-
if !part2_a_finished && a % 4 == 0 {
115+
if !part2_a_finished && a.is_multiple_of(4) {
116116
part2_a_values.push(a as u16);
117117
}
118-
if !part2_b_finished && b % 8 == 0 {
118+
if !part2_b_finished && b.is_multiple_of(8) {
119119
part2_b_values.push(b as u16);
120120
}
121121
}

crates/year2017/src/day22.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl Day22 {
3939
b'#' => Some(State::Infected),
4040
_ => None,
4141
})?;
42-
if rows != cols || rows % 2 == 0 {
42+
if rows != cols || rows.is_multiple_of(2) {
4343
return Err(InputError::new(input, 0, "expected odd size square grid"));
4444
}
4545
Ok(Self { size: rows, grid })

crates/year2018/src/day11.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ impl Day11 {
4040
let (mut max_size, mut max_total, mut max_x, mut max_y) = (0, i32::MIN, 0, 0);
4141
let mut sizes: Vec<i32> = Vec::with_capacity(300);
4242

43-
for size in 1..=300 {
43+
for size in 1usize..=300 {
4444
// Try to split the N*N square into Y X*X squares to calculate an upper bound.
4545
// For example, if the best 5x5 is 100, then the best 10x10 must be <= 400.
46-
if let Some(divisor) = (2..=size / 2).rev().find(|&d| size % d == 0) {
46+
if let Some(divisor) = (2..=size / 2).rev().find(|&d| size.is_multiple_of(d)) {
4747
let copies = (size / divisor) * (size / divisor);
4848
let upper_bound = sizes[divisor - 1].saturating_mul(copies as i32);
4949
if upper_bound < max_total {

crates/year2024/src/day07.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl Day07 {
4545
return target == next;
4646
}
4747

48-
(target % next == 0 && Self::possible(target / next, numbers, concat))
48+
(target.is_multiple_of(next) && Self::possible(target / next, numbers, concat))
4949
|| (concat && {
5050
// All the numbers are 1-3 digits, which makes this faster than
5151
// let pow = 10u64.pow(next.ilog10() + 1);

0 commit comments

Comments
 (0)