[Coco] Project Euler and the Coco

John johnguin at hotmail.com
Fri Nov 14 21:53:08 EST 2008


Hello all,

I'm sure by now many of you have seen Project Euler"at
http://projecteuler.net/.

If not, they have math problems to solve.  One example is the 9th easiest:
Find the product of a,b,c such that a^2 + b^2 = c^2 and a+b+b=1000.

I used my Coco2 to solve this problem in 11 and a half minutes using the
high speed poke.  At the risk of flooding the list with BASIC code, I hope
my short program here will spur comments and optimizations:

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

For example, one optimization became clear after I had the answer.  As a
hint, I could cut run time by about 40%...

I hope everyone has some fun with these,
John




More information about the Coco mailing list