Pythagorean triples: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: added syntax colouring the hard way)
m (Small changes to program; don't affect result.)
Line 1,182: Line 1,182:
Counts (1) all Pythagorean triples (2) primitive Pythagorean triples,
Counts (1) all Pythagorean triples (2) primitive Pythagorean triples,
with perimeter not greater than a given value.
with perimeter not greater than a given value.

Library subroutine M3, Prints header and is then overwritten.
Library subroutine M3, Prints header and is then overwritten.
Here, the last character sets the teleprinter to figures.]
Here, the last character sets the teleprinter to figures.]
Line 1,189: Line 1,189:
@&*!MAX!PERIM!!!!!TOTAL!!!!!!PRIM@&#.
@&*!MAX!PERIM!!!!!TOTAL!!!!!!PRIM@&#.
..PZ
..PZ

[Library subroutine P7, prints long strictly positive integer;
[Library subroutine P7, prints long strictly positive integer;
10 characters, right justified, padded left with spaces.
10 characters, right justified, padded left with spaces.
Line 1,196: Line 1,196:
GKA3FT26@H28#@NDYFLDT4DS27@TFH8@S8@T1FV4DAFG31@SFLDUFOFFFSFL4F
GKA3FT26@H28#@NDYFLDT4DS27@TFH8@S8@T1FV4DAFG31@SFLDUFOFFFSFL4F
T4DA1FA27@G11@XFT28#ZPFT27ZP1024FP610D@524D!FO30@SFL8FE22@
T4DA1FA27@G11@XFT28#ZPFT27ZP1024FP610D@524D!FO30@SFL8FE22@

[Subroutine for positive integer division.
[Subroutine for positive integer division.
Input: 4D = dividend, 6D = divisor.
Input: 4D = dividend, 6D = divisor.
Line 1,204: Line 1,204:
GKA3FT35@A6DU8DTDA4DRDSDG13@T36@ADLDE4@T36@T6DA4DSDG23@
GKA3FT35@A6DU8DTDA4DRDSDG13@T36@ADLDE4@T36@T6DA4DSDG23@
T4DA6DYFYFT6DT36@A8DSDE35@T36@ADRDTDA6DLDT6DE15@EFPF
T4DA6DYFYFT6DT36@A8DSDE35@T36@ADRDTDA6DLDT6DE15@EFPF

[Subroutine to return GCD of two non-negative 35-bit integers.
[Subroutine to return GCD of two non-negative 35-bit integers.
Input: Integers at 4D, 6D.
Input: Integers at 4D, 6D.
Line 1,212: Line 1,212:
GKA3FT39@S4DE37@T40@A4DTDA6DRDSDG15@T40@ADLDE6@T40@A6DSDG20@T6D
GKA3FT39@S4DE37@T40@A4DTDA6DRDSDG15@T40@ADLDE6@T40@A6DSDG20@T6D
T40@A4DSDE29@T40@ADRDTDE16@S6DE39@TDA4DT6DSDT4DE5@A6DT4DEFPF
T40@A4DSDE29@T40@ADRDTDE16@S6DE39@TDA4DT6DSDT4DE5@A6DT4DEFPF

[************************ ROSETTA CODE TASK *************************
[************************ ROSETTA CODE TASK *************************
Subroutine to count Pythagorean triples with given maximum perimeter.
Subroutine to count Pythagorean triples with given maximum perimeter.
Line 1,225: Line 1,225:
A 3 F [make link]
A 3 F [make link]
E 16 @ [jump over variables and constants]
E 16 @ [jump over variables and constants]

[Double values are put here to ensure even address]
[Double values are put here to ensure even address]
[Variables]
[Variables]
Line 1,234: Line 1,234:
[10] P F P F [n]
[10] P F P F [n]
[Constants]
[Constants]
T12#Z PF T12Z [clears sandwich digit between 12 and 13]
[12] P D P F [double-value 1]
[12] P D P F [double-value 1]
T14#Z PF T14Z [clears sandwich digit between 14 and 15]
[14] P1F P F [double-value 2]
[14] P1F P F [double-value 2]

[Continue with code]
[Continue with code]
[16] T 69 @ [plant link for return]
[16] T 69 @ [plant link for return]
Line 1,300: Line 1,302:
T 6 D [return in 6D]
T 6 D [return in 6D]
[69] E F
[69] E F

[2nd-level subroutine to count triangles arising from m, n.
[2nd-level subroutine to count triangles arising from m, n.
Assumes m, n are coprime and of opposite parity,
Assumes m, n are coprime and of opposite parity,
Line 1,329: Line 1,331:
T 6 D [return count = 0]
T 6 D [return count = 0]
[91] E F
[91] E F

[Main routine. Load at an even address.]
[Main routine. Load at an even address.]
T 500 K
T 500 K
G K
G K
[The initial maximum perimeter is repeatedly multiplied by 10]
[The initial maximum perimeter is repeatedly multiplied by 10]
T#Z PF TZ [clears sandwich digit between 0 and 1]
[0] P50F PF [initial maximum perimeter <---------- EDIT HERE]
[0] P50F PF [initial maximum perimeter <---------- EDIT HERE]
[2] P 3 F [number of values to calculate <---------- EDIT HERE]
[2] P 3 F [number of values to calculate <---------- EDIT HERE]