[Coco] Project Euler and the Coco
da3m0n_slay3r at yahoo.com
Sat Nov 15 01:41:52 EST 2008
Line 40: the OR clause in the if statement slows things down, because once C >= A, then it tests BOTH C < A AND C < B. So Drop the "C<A OR" part to save time. it still fits A < B < C.
40 IF C < B THEN 60
Also for CoCo: renumber to make lines less than double digits and triple digits. I'd say remove spaces too, but our readability would suffer.
As far as precalc-ing A*A, would there not be an increase in speed to also precalc B*B and C*C?
-Later! -WB- -- BABIC Computer Consulting.
--- On Fri, 11/14/08, Mark McDougall <msmcdoug at iinet.net.au> wrote:
> From: Mark McDougall <msmcdoug at iinet.net.au>
> Subject: Re: [Coco] Project Euler and the Coco
> To: "CoCoList for Color Computer Enthusiasts" <coco at maltedmedia.com>
> Date: Friday, November 14, 2008, 10:12 PM
> John wrote:
> > 10 FOR A = 2 TO 333
> > 20 FOR B = 334 TO 667
> > 30 C = 1000 -A -B
> > 40 IF C<A OR C<B THEN 60
> > 50 IF A*A + B*B = C*C THEN 100
> > 60 NEXT B,A
> > 100 PRINT "A="A
> > 110 PRINT "B="B
> > 120 PRINT "C="C
> > 130 PRINT "A X B X C ="A*B*C
> Not sure whether you mean algorithm optimisation, code
> optimisation, or both?
> 1. 20 FOR B=500-A TO 500+A gives result 40% quicker
> 2. pre-calc A*A at line 15 to run quicker
> that's all I can see so far...
> -- | Mark McDougall |
> "Electrical Engineers do it
> | <http://members.iinet.net.au/~msmcdoug> | with
> less resistance!"
> Coco mailing list
> Coco at maltedmedia.com
More information about the Coco