Skip to content

Optimization of Triangle Number Sum - #64

Open
davis-matthew wants to merge 1 commit into
maxscheurer:masterfrom
davis-matthew:oeis-closed-form
Open

davis-matthew wants to merge 1 commit into
maxscheurer:masterfrom
davis-matthew:oeis-closed-form

Conversation

@davis-matthew

Copy link
Copy Markdown

Replaced summation loop of triangle sums with the closed-form formula. Originally found by matching against OEIS A000292.

Overflow will happen earlier with this version, although no reasonable order would get anywhere close so I'm assuming that's not an issue. I can replace it with analogous division before multiplication code if desired as it's possible to prove one of the terms is divisible by 3, and either p+1 or p+2 should be even and divisible by 2.

I left TriangleNumbers as a utility, although it may not be needed anymore as it is not referenced externally and was only used for this calculation.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant