Post Reply 
(12C) Pythagorean Triple
09-18-2019, 11:37 AM (This post was last modified: 09-19-2019 12:48 AM by Gamo.)
Post: #1
(12C) Pythagorean Triple
Program to generate a Pythagorean Triples based on this formula

a = m^2 - n^2 , b = 2mn , c = m^2 + n^2

for m > n with m and n co-prime and not both odd

-------------------------------------------------
Procedure: FIX 0

Your choice of integer m > n

m [ENTER] n [R/S] display answer a ... b ... c [R/S] add one on both m and n and display next result.

To start over with new pair of m and n f [PRGM]
-------------------------------------------------
example: f [PRGM]

m = 2 , n = 1

2 [ENTER] 1 display 3 .... 4 .... 5 [R/S] 5 ... 12 ... 13

To review result use [R↓] [R↓] [R↓]

--------------------------------------------------
Program:
Code:

01 STO 2  // n
02 R↓
03 STO 1  // m
04 RCL 1
05 RCL 2
06  -
07 LSTx
08 X<>Y
09 ENTER
10  x
-------------
11 √x
12 X=0
13 GTO 15
14 GTO 06
15 X<>Y  // GCD routine
16  1
17  -
18 X=0  // Test for a co-prime
19 GTO 24
20  1
-----------
21 STO+1
22 STO+2
23 GTO 04
24 RCL 1
25  2
26  ÷
27 FRAC
28 X=0  // Test for odd or even integer
29 GTO 39
30 RCL 2
-----------
31  2
32  ÷
33 FRAC
34 X=0  // Test to make sure not both odd integer
35 GTO 39
36  1
37 STO+1
38 GTO 04
39 RCL 1
40 ENTER
-----------
41  x
42 RCL 2
43 ENTER 
44  x
45  +
46 STO 3
47 RCL 1
48 RCL 2
49  x
50  2
----------
51  x
52 STO 4
53 RCL 1
54 ENTER
55  x
56 RCL 2
57 ENTER 
58  x
59  -
60  0
----------
61 X<>Y
62 PSE  // display a
63 RCL 4
64 PSE // display b
65 RCL 3  // display c
66 R/S
67  1
68 STO+1
69 STO+2
70 GTO 04  // add one and start over

Gamo
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(12C) Pythagorean Triple - Gamo - 09-18-2019 11:37 AM
RE: (12C) Pythagorean Triple - Albert Chan - 09-20-2019, 04:33 PM



User(s) browsing this thread: 1 Guest(s)