Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: The hardest...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 23 Topic 4031 of 4287
Post > Topic >>

Re: The hardest Euler problem

by mhx@[EMAIL PROTECTED] (Marcel Hendrix) May 4, 2008 at 09:13 AM

cac <cac@[EMAIL PROTECTED]
> writes Re: The hardest Euler problem
[..]
>> Someone posted this PARI/GP solution to problem 12:
 
>> n=0; until(numdiv(n*(n+1)/2) > 500, n++); n*(n+1)/2

>> He said it took about 50ms on his Intel 2.52GHz.

What else to expect with a built-in number-of-divisors function? 

> Sigh. My solution takes 1h45m. I think maybe PARI/GP knows things about
> factoring that I don't.

What you can easily see is that one only needs to count to below the 
square root of u1, because each successful division delivers you two 
valid divisors. If you take that into account, you solve the problem
in 800 ms (so short that I didn't think about making it faster).
The only (1-off ) complication is that u1 could be a perfect square 
(however, it follows from the formula it can't).

Assuming you are doing this in Forth (why else mention it here):

: #divisors ( u1 -- u2 )
	0 swap
	dup s>f fsqrt fround f>s 1+  ( prefect square?)
	1 ?do  dup i mod 0= 2 and rot + swap  loop  drop ;

> I didn't have much problem with 191. 192 on the other hand... I whipped
> out some code, looks good, runs quick, gets the wrong answer...

I also find that some of the higher-numbered problems can be surprisingly
simple. Unfortunately, some others can waste a day (44, 45 I can't solve
by brute force).

-marcel
 




 23 Posts in Topic:
The hardest Euler problem
Albert van der Horst <  2008-05-02 11:05:34 
Re: The hardest Euler problem
mhx@[EMAIL PROTECTED] (M  2008-05-02 14:18:00 
Re: The hardest Euler problem
Albert van der Horst <  2008-05-02 16:09:01 
Re: The hardest Euler problem
cac <cac@[EMAIL PROTEC  2008-05-02 07:40:21 
Re: The hardest Euler problem
William James <w_a_x_m  2008-05-03 17:06:22 
Re: The hardest Euler problem
cac <cac@[EMAIL PROTEC  2008-05-03 21:36:56 
Re: The hardest Euler problem
cac <cac@[EMAIL PROTEC  2008-05-03 22:27:03 
Re: The hardest Euler problem
mhx@[EMAIL PROTECTED] (M  2008-05-04 09:13:22 
Re: The hardest Euler problem
cac <cac@[EMAIL PROTEC  2008-05-04 01:31:32 
Re: The hardest Euler problem
mhx@[EMAIL PROTECTED] (M  2008-05-04 13:08:37 
Re: The hardest Euler problem
cac <cac@[EMAIL PROTEC  2008-05-04 19:00:19 
Re: The hardest Euler problem
mhx@[EMAIL PROTECTED] (M  2008-05-04 15:41:04 
Re: The hardest Euler problem
anton@[EMAIL PROTECTED]   2008-05-04 13:47:12 
Re: The hardest Euler problem
William James <w_a_x_m  2008-05-05 08:08:17 
Re: The hardest Euler problem
Jonah Thomas <jethomas  2008-05-04 22:51:46 
Re: The hardest Euler problem
cac <cac@[EMAIL PROTEC  2008-05-04 20:44:33 
Re: The hardest Euler problem
William James <w_a_x_m  2008-05-05 10:22:58 
Re: The hardest Euler problem
anton@[EMAIL PROTECTED]   2008-05-05 17:49:46 
Re: The hardest Euler problem
Alex McDonald <blog@[E  2008-05-15 05:20:01 
Re: The hardest Euler problem
Alex McDonald <blog@[E  2008-05-15 06:47:58 
Re: The hardest Euler problem
foxchip <fox@[EMAIL PR  2008-05-23 17:08:24 
Re: The hardest Euler problem
GiulioDeVecchi@[EMAIL PRO  2008-05-15 00:56:07 
Re: The hardest Euler problem
Albert van der Horst <  2008-05-05 00:01:12 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Oct 13 3:28:40 CDT 2008.