Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
59
Task/Pythagorean-triples/ERRE/pythagorean-triples.erre
Normal file
59
Task/Pythagorean-triples/ERRE/pythagorean-triples.erre
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
PROGRAM PIT
|
||||
|
||||
BEGIN
|
||||
|
||||
PRINT(CHR$(12);) !CLS
|
||||
PRINT(TIME$)
|
||||
|
||||
FOR POWER=1 TO 7 DO
|
||||
PLIMIT=10#^POWER
|
||||
UPPERBOUND=INT(1+PLIMIT^0.5)
|
||||
PRIMITIVES=0
|
||||
TRIPLES=0
|
||||
EXTRAS=0 ! will count the in-range multiples of any primitive
|
||||
|
||||
FOR M=2 TO UPPERBOUND DO
|
||||
FOR N=1+(M MOD 2=1) TO M-1 STEP 2 DO
|
||||
TERM1=2*M*N
|
||||
TERM2=M*M-N*N
|
||||
TERM3=M*M+N*N
|
||||
PERIMETER=TERM1+TERM2+TERM3
|
||||
|
||||
IF PERIMETER<=PLIMIT THEN TRIPLES=TRIPLES+1
|
||||
|
||||
A=TERM1
|
||||
B=TERM2
|
||||
|
||||
REPEAT
|
||||
R=A-B*INT(A/B)
|
||||
A=B
|
||||
B=R
|
||||
UNTIL R<=0
|
||||
|
||||
! we've found a primitive triple if a = 1, since hcf =1.
|
||||
! and it is inside perimeter range. Save it in an array
|
||||
IF (A=1) AND (PERIMETER<=PLIMIT) THEN
|
||||
PRIMITIVES=PRIMITIVES+1
|
||||
|
||||
!-----------------------------------------------
|
||||
!swap so in increasing order of side length
|
||||
!-----------------------------------------------
|
||||
IF TERM1>TERM2 THEN SWAP(TERM1,TERM2)
|
||||
!-----------------------------------------------
|
||||
!we have the primitive & removed any multiples.
|
||||
!Now calculate ALL the multiples in range.
|
||||
!-----------------------------------------------
|
||||
NEX=INT(PLIMIT/PERIMETER)
|
||||
EXTRAS=EXTRAS+NEX
|
||||
END IF
|
||||
|
||||
!scan
|
||||
END FOR
|
||||
END FOR
|
||||
|
||||
PRINT("Primit. with perimeter <=";10#^power;"is";primitives;"&";extras;"non-prim.triples.")
|
||||
PRINT(TIME$)
|
||||
END FOR
|
||||
|
||||
PRINT PRINT("** End **")
|
||||
END PROGRAM
|
||||
Loading…
Add table
Add a link
Reference in a new issue