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()); }