! ==== testkib.factor ==== ! Copyright Kibleur Christophe - 2008 ! Computes the gcd of 2 integers IN: testkib ! launch with ./factor testkib.factor USING: prettyprint math math.order kernel ; : pgcd ( a b -- c ) ! We first need to swap a and b if a < b 2dup < [ swap ] when ! Computation : 2dup ! Stack is now : a b a b mod dup ! Stack is now : a b r r (where r is the remainder) ! If remainder is null, returns b zero? [ drop min ] ! stack was sort of : a b r f/t so it becomes a b ! else call pgcd on b and remainder [ min pgcd ] if ; ! this is also possible : 411 685 pgcd . 685 411 pgcd .