Skip to content

Commit

Permalink
Remove need for std::ops::Neg by distributing negatives
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Sep 9, 2024
1 parent b324bf9 commit 06f98c2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion rust/src/include/ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where I: NumAssign + PartialOrd
let length = if step > zero() && start < stop {
one::<I>() + (stop - one() - start) / step
} else if step < zero() && start > stop {
one::<I>() + (start - one() - stop) / (-step)
one::<I>() + (stop + one() - start) / step
} else {
zero::<I>()
};
Expand Down
10 changes: 5 additions & 5 deletions rust/src/problems/p0028.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit 06f98c2

Please sign in to comment.