Skip to content

Commit

Permalink
Minor tweaks to force a re-run
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Jul 25, 2024
1 parent 5110511 commit cd75724
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions c/p0076.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ unsigned int p0076() {
sum += counts[i];
}
}

return answer;
}

Expand Down
1 change: 1 addition & 0 deletions cplusplus/p0076.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ unsigned int p0076() {
sum += counts[i];
}
}

return answer;
}

Expand Down
1 change: 1 addition & 0 deletions csharp/Euler/p0004.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public Task<Int64> Answer()
}
}
}

return Task.FromResult<Int64>(answer);
}
}
Expand Down
2 changes: 1 addition & 1 deletion javascript/p0000_template.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
**/

exports.p0000 = function() {

return 0;
};
11 changes: 6 additions & 5 deletions python/p0357.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""
Project Euler Problem 357
A key note is that n // d is always also a factor, so it ends up being pairs. This means you can halve your search space
A key note is that n // d is always also a factor, so it ends up being pairs.
This means you can halve your search space
Problem:
Expand All @@ -13,16 +14,16 @@
Revision 1:
Prime filter cuts by a little more than half, but I think this is mostly from the cache benefits on is_prime().
Prime square filter shaves off an additional ~8%.
Prime filter cuts by a little more than half, but I think this is mostly from the
cache benefits on is_prime(). Prime square filter shaves off an additional ~8%.
without negating its benefit, or figure out a more general solution to the filter.
Filtering to evens also shaves off some more, and n=4k+2 goes even further, about 45%.
This cuts it overall from ~20 minutes to ~5 minutes.
Revision 2:
Using the :py:func:`proper_divisors <python.p0021.proper_divisors>` function from p0021 speeds this up by ~11%, going
from 2:26 to 2:10
Using the :py:func:`proper_divisors <python.p0021.proper_divisors>` function from
p0021 speeds this up by ~11%, going from 2:26 to 2:10
"""
from typing import Iterable

Expand Down
12 changes: 5 additions & 7 deletions rust/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::mem::size_of;
use num_traits::NumAssign;
use num_traits::one;

const MAX_FACTORIAL: [usize; 16] = [
const MAX_FACTORIAL: [u8; 16] = [
5, // u8
8, // u16
10, 12, // u32
Expand All @@ -28,17 +28,15 @@ where I: Copy + From<u8> + From<u64> + NumAssign + PartialOrd
if n < r {
panic!("Out of function's bounds");
}
if n < MAX_FACTORIAL[size_of::<I>() as usize] {
if n < MAX_FACTORIAL[size_of::<I>() as usize] as usize {
return factorial::<I>(n as u8) / factorial::<I>(r as u8);
}
// slow path for larger numbers
let mut answer: I = one();
let mut tmp: I;
let mut factors: Vec<i8> = vec![0; n + 1];
// collect factors of final number
for i in 2..=n {
factors[i] = 1;
}
let mut factors: Vec<i8> = vec![1; n + 1];
factors[0] = 0;
factors[1] = 0;
// negative factor values indicate need to divide
for i in 2..=r {
factors[i] -= 1;
Expand Down

0 comments on commit cd75724

Please sign in to comment.