SQPQ - Square Root's Partial Quotients, by Joe Horn, 12/28/92. A Number Theory tool. Turning square roots of integers into continued fractions via the usual FP INV method rapidly introduces round-off errors, and does not help in determining where the continued fraction begins to repeat. The following program, SQPQ, uses a method which neatly avoids all round-off errors and automatically detects where the repetition begins. INSTRUCTIONS: SQPQ takes the integer (not its square root!) as its input, and returns a list of the partial quotients of the continued fraction equal to the square root of the input. The list terminates immediately after the last term of the repeating sequence. Therefore the entire list, except for the first element, repeats. EXAMPLE: What is the continued fraction for the square root of 18? 18 SQPQ --> { 4 4 8 } which means SQRT(18) = 4+1/(4+1/(8+1/(4+1/(8+... with 4 8 repeating. EXAMPLE: 28 SQPQ --> { 5 3 2 3 10 } which means SQRT(28) = 5+1/(3+1/(2+1/(3+1/(10+1/(3+1/(2+1/(3+1/(10+... with 3 2 3 10 repeating. EXAMPLE: 16 SQPQ --> { 4 } which means it's exactly 4. %%HP: T(3)A(D)F(.); @ SQPQ, Square Root's Partial Quotients, by Joe Horn, 12/28/92 \<< DUP \v/ IF DUP FP THEN 0 1 1 \-> N S A B L \<< DO S A + B / IP DUP B * A - 'A' STO N A SQ - B / 'B' STO 'L' 1 STO+ UNTIL B 1 == END A DUP + L \->LIST \>> ELSE SWAP DROP 1 \->LIST END \>>