;??-May-1999                                                    Alain Brobecker
;Algorithm to search the GCD (given by Frederic Elisei)
;While A<>B we replace the greatest by the difference

 8784840814172354341
 COPY 34184 *
 COPY2 "GCD(" HPRINT ";" HPRINT ")=" CR

 COPY2 TIME 3 SWAP
 GCDr
 TIME 3 SWAP DROP
 "Recursive: " HPRINT SWAP2 - " (" HPRINT " cs)" CR

 COPY2 TIME 3 SWAP
 GCDi
 TIME 3 SWAP DROP
 "Iterative: " HPRINT SWAP2 - " (" HPRINT " cs)" CR
END

;Recursive version
;IN         B A
;OUT        GCD(B;A) GCD(B;A)
#GCDr
  COPY2 SKIP<> END      ;If B=A it is the GCD
  COPY2 SKIP< SWAP2     ;After this we have B<A
  COPY2 DROP            ;B A B
  -                     ;B (A-B)
  GCDr                  ;Easy recursion, isn't it?
END

;Iterative version
;IN         B A
;OUT        GCD(B;A) GCD(B;A)
#GCDi
  COPY2 SKIP<> END
.GCDl
  COPY2 SKIP< SWAP2     ;After this line we have B<A
  COPY2 DROP            ;B A B
  -                     ;B (A-B)
  COPY2 SKIP= GCDl      ;loop while they are different
END