From 06f98c20dce30b4739b6dc6c670422c9fce65461 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Sun, 8 Sep 2024 21:25:00 -0500 Subject: [PATCH] Remove need for std::ops::Neg by distributing negatives --- rust/src/include/ranges.rs | 2 +- rust/src/problems/p0028.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rust/src/include/ranges.rs b/rust/src/include/ranges.rs index 4ee4b838..b5b8cd40 100644 --- a/rust/src/include/ranges.rs +++ b/rust/src/include/ranges.rs @@ -14,7 +14,7 @@ where I: NumAssign + PartialOrd let length = if step > zero() && start < stop { one::() + (stop - one() - start) / step } else if step < zero() && start > stop { - one::() + (start - one() - stop) / (-step) + one::() + (stop + one() - start) / step } else { zero::() }; diff --git a/rust/src/problems/p0028.rs b/rust/src/problems/p0028.rs index 3c17e06a..28716b13 100644 --- a/rust/src/problems/p0028.rs +++ b/rust/src/problems/p0028.rs @@ -52,11 +52,11 @@ use crate::include::utils::Answer; pub fn p0028() -> Answer { let mut answer: u32 = 1; for i in 1..(1002 / 2) { - let start = (2 * i - 1)**2 + 1; - answer += range_entry3(start, 1, (1 * 2 * i - 1)) + - range_entry3(start, 1, (2 * 2 * i - 1)) + - range_entry3(start, 1, (3 * 2 * i - 1)) + - range_entry3(start, 1, (4 * 2 * i - 1)); + let start = (2 * i - 1).pow(2) + 1; + answer += range_entry3(start, 1, 1 * 2 * i - 1) + + range_entry3(start, 1, 2 * 2 * i - 1) + + range_entry3(start, 1, 3 * 2 * i - 1) + + range_entry3(start, 1, 4 * 2 * i - 1); } return Answer::Int(answer.into()); }