[Coco] Project Euler and the Coco

Arthur Flexser flexser at fiu.edu
Sat Nov 15 06:27:46 EST 2008


I just thought of a simpler and easier way to explain how to get the appropriate
upper limit for B:

Imagine a board of length 1000, to be divided into 3 pieces, A, B, and C, of
ascending size.  Whatever the size of A is (and it can't exceed 1/3 of the total
length, to achieve ascending lengths), the remaining 1000-A of length must be
divided between B and C.  The ascending length requirement means that B must
take up no more than half of the remaining board, or (1000-A)/2.  My expression
A+INT((1000-3*A-1)/2) for the maximum value of B simplifies to that, if we
disregard the '-1' that is the minimum required difference between B and C.

Art


On Sat, 15 Nov 2008, Arthur Flexser wrote:

> I think the limits aren't right.  Here's how I figure it:
> 
> Since we want a <= b < c, let b=a+d1 and c=b+d2, where d1 >= 0 and d2 > 0.  
> Then a+b+c=1000 is equivalent to a+(a+d1)+((a+d1)+d2)=1000, or 3a+2d1+d2=1000.  
> The minimum value of d1, the difference between b and a, is 0;  what is its
> maximum?  For a given value of a, the maximum of d1 occurs when d2 assumes its
> minimum value of one, giving d1=(1000-3a-1)/2.  So, I'd start with
> 
>  10 FOR A=1 TO 333 (why is A=1 excluded in the original?) 
>  20 BH=A+INT((1000-3*A-1)/2): A2=A*A 
>  30 FOR B=A TO BH 
> 
> etc.
> 
> Since this upper limit for B guarantees that C will exceed A and B, the check in
> line 40 may be omitted.
> 
> I see no apparent reason why B must be in the range 334 to 667, as John
> assumed.  Why exclude, for example, the abc combination 200, 300, 500, which
> properly adds to 1000, from testing?
> 
> Art
> 
> On Fri, 14 Nov 2008, John wrote:
> 
> > 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
> > 
> > 
> > --
> > Coco mailing list
> > Coco at maltedmedia.com
> > http://five.pairlist.net/mailman/listinfo/coco
> > 
> 
> 
> 
> 
> --
> Coco mailing list
> Coco at maltedmedia.com
> http://five.pairlist.net/mailman/listinfo/coco
> 




More information about the Coco mailing list