Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
PHP projecteuler.net problem 12 // fancy code optimization? [solved]
I’m trying to learn some PHP so I embarked on Project Euler. So far it has been something in between jolly good fun and having tendencies to gobble up live goats out of frustration.
I’m up to problem 12, and the solution I’ve created is way too slow (beyond waiting for it to finish slow), so I was hoping some more advanced coders could help me clean and speed it up: here’s the pastie
This is the problem statement:
The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, …
Let us list the factors of the first seven triangle numbers:
1: 1 3: 1,3 6: 1,2,3,6
10: 1,2,5,10
15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28
We can see that 28 is the first triangle number to have over five divisors.What is the value of the first triangle number to have over five hundred divisors?
edit: blast: the while ($delers < 500) {
in the pastie should be while ($delers < 501) {
Now… let me kill apache again…
edit: I guess I ought to post this at a php forum
edit2 : got a solution there
Last edited by JanDW (2009-10-13 01:11:29)
TXPDream – A Textpattern Tag Library for Adobe Dreamweaver. (updated for 4.2.0) | jdw_if_ajax – Only serve certain parts of a page when requested with AJAX
Offline