We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 85780e0 commit 334cab4Copy full SHA for 334cab4
Project-Euler/Problem044.js
@@ -22,9 +22,17 @@ function problem44(k) {
22
23
for (let j = k - 1; j > 0; j--) {
24
const m = (j * (3 * j - 1)) / 2 // calculate all Pj < Pk
25
- if (isPentagonal(n - m) && isPentagonal(n + m)) {
26
- // Check sum and difference
27
- return n - m // return D
+ // Check forward, checking n - m doubles work from previous iterations
+ const sum = n + m
+ if (isPentagonal(sum)) {
28
+ // Check sum - m = n
29
+ if (isPentagonal(sum + m)) {
30
+ return n // return D
31
+ }
32
+ // Check sum - n = m
33
+ if (isPentagonal(sum + n)) {
34
+ return m // return D
35
36
}
37
38
0 commit comments