(42S) GCD

07102016, 01:39 AM
(This post was last modified: 06152017 01:16 PM by Gene.)
Post: #1




(42S) GCD
HP 42S: GCD (Greatest Common Divisor) by Euclid Division
Enter the two integers on the Y stack and X stack. Order doesn’t matter. Code: 00 {42Byte Prgm} Test: Find the GCD of 485 and 175. 485 [ENTER] 175 [XEQ] {GCD} Result: 5 Alternatively: 175 [ENTER] 485 [XEQ] {GCD} Result: 5 

07122016, 03:48 AM
Post: #2




RE: (42) GCD
As others have recently posted in parallel discussions, the GCD routine in the PPC ROM is probably the shortest and fastest possible:
LBL c MOD LASTX X<>Y X\=0? ("not equal to zero?") GTO c + RTN Instructions: Same. Output: GCD is returned in X. X<> c Joe 

07122016, 06:23 AM
Post: #3




RE: (42) GCD
(07122016 03:48 AM)Joe Horn Wrote: As others have recently posted in parallel discussions, the GCD routine in the PPC ROM is probably the shortest and fastest possible: Also posted in the other GCD thread: You can get it one step shorter (but with the same byte count): Code: LBL d Note to HP42 users: STO Z is STO ST Z. Dieter 

07122016, 06:40 AM
(This post was last modified: 07122016 06:40 AM by Paul Dale.)
Post: #4




RE: (42) GCD
Of the 34S you can do even better:
Code: 01 GCD  Pauli 

07132016, 09:59 AM
Post: #5




RE: (42) GCD  
08172017, 02:23 PM
Post: #6




RE: (42S) GCD
(07102016 01:39 AM)Eddie W. Shore Wrote: GCD (Greatest Common Divisor) by Euclid There is a 15C version as per Marcus du Sautoy explanation (in TV show 'Secrets Of Modern Living: Algorithms') Code:
Deatiled discussion is here: Calculator Google Group  GCD (Euclid's Algorithm) In that thread another version is available for SENCOR SEC103, which is a perfect clone of CASIO fx3650P (but much cheaper, much faster and most precise ) Csaba 

02132018, 09:57 PM
(This post was last modified: 02132018 10:00 PM by Logan.)
Post: #7




RE: (42S) GCD
(07122016 06:23 AM)Dieter Wrote: Also posted in the other GCD thread: I tried to come up with my own method to do this (after reading about Euclid's Algorithm), and once I had did a search to see what others had come up with. I was proud to see that the one I'd come up with was identical to this with the exception that I swapped X<>Y at the end instead of the addition. 

« Next Oldest  Next Newest »

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