Post Reply 
Favorite HP-41 programs and techniques
01-28-2021, 06:31 PM
Post: #4
RE: Favorite HP-41 programs and techniques
(01-28-2021 03:55 PM)smartin Wrote:  What are your favorite well-crafted FOCAL programs?


The Greatest Common Divisor & Lowest Common Multiple routine that computes GCD(a,b) & LCM(a,b) and calculates a' = a/GCD(a,b) & b' = b/GCD(a,b) without the use of any flag, registre, subroutine or specific module in no more than sixteen steps.

Code:

 01  LBL "GCD"
 02    RCL Y  RCL Y
 04    LBL 01  MOD  LASTX  X<>Y  X#0?  GTO 01
 10    +  ST/ T  /  ST* Y  X<>Y  LASTX
 16  END   ( 29 bytes / SIZE 000 )

Code:
     STACK           INPUTS         OUTPUTS
           T                /       a'= a/gcd(a,b)
           Z                /       b'= b/gcd(a,b)
           Y                a           lcm(a,b)
           X                b           gcd(a,b)
           L                /           gcd(a,b)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Favorite HP-41 programs and techniques - C.Ret - 01-28-2021 06:31 PM



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