From cd75724481d2300d5b3a1422b16317e817c61cb2 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Thu, 25 Jul 2024 00:45:20 -0500 Subject: [PATCH] Minor tweaks to force a re-run --- c/p0076.c | 1 + cplusplus/p0076.cpp | 1 + csharp/Euler/p0004.cs | 1 + javascript/p0000_template.js | 2 +- python/p0357.py | 11 ++++++----- rust/src/math.rs | 12 +++++------- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/c/p0076.c b/c/p0076.c index a8764b88..a76e9e26 100644 --- a/c/p0076.c +++ b/c/p0076.c @@ -67,6 +67,7 @@ unsigned int p0076() { sum += counts[i]; } } + return answer; } diff --git a/cplusplus/p0076.cpp b/cplusplus/p0076.cpp index a3fa755c..0575a74c 100644 --- a/cplusplus/p0076.cpp +++ b/cplusplus/p0076.cpp @@ -67,6 +67,7 @@ unsigned int p0076() { sum += counts[i]; } } + return answer; } diff --git a/csharp/Euler/p0004.cs b/csharp/Euler/p0004.cs index 6cb610cd..44b7ab48 100644 --- a/csharp/Euler/p0004.cs +++ b/csharp/Euler/p0004.cs @@ -45,6 +45,7 @@ public Task Answer() } } } + return Task.FromResult(answer); } } diff --git a/javascript/p0000_template.js b/javascript/p0000_template.js index 4f11b2d1..b95c0b1a 100644 --- a/javascript/p0000_template.js +++ b/javascript/p0000_template.js @@ -11,5 +11,5 @@ **/ exports.p0000 = function() { - + return 0; }; diff --git a/python/p0357.py b/python/p0357.py index 628297b5..12a82308 100644 --- a/python/p0357.py +++ b/python/p0357.py @@ -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: @@ -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 ` function from p0021 speeds this up by ~11%, going -from 2:26 to 2:10 +Using the :py:func:`proper_divisors ` function from +p0021 speeds this up by ~11%, going from 2:26 to 2:10 """ from typing import Iterable diff --git a/rust/src/math.rs b/rust/src/math.rs index 02a00996..03102fdd 100644 --- a/rust/src/math.rs +++ b/rust/src/math.rs @@ -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 @@ -28,17 +28,15 @@ where I: Copy + From + From + NumAssign + PartialOrd if n < r { panic!("Out of function's bounds"); } - if n < MAX_FACTORIAL[size_of::() as usize] { + if n < MAX_FACTORIAL[size_of::() as usize] as usize { return factorial::(n as u8) / factorial::(r as u8); } // slow path for larger numbers let mut answer: I = one(); let mut tmp: I; - let mut factors: Vec = vec![0; n + 1]; - // collect factors of final number - for i in 2..=n { - factors[i] = 1; - } + let mut factors: Vec = 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;