Greatest Common Divisor

From mojo_puzzler
Revision as of 15:53, 17 November 2023 by Gneale (talk | contribs) (Created page with "===== Return to: Chialisp ===== ===== Return to: Recursive Functions ===== (mod (num1 num2) (defun remainder (x y) (r (divmod x y))) (defun gcd (num1 num2) (if (= num2 0) num1 (gcd num2 (remainder num1 num2)))) (gcd num1 num2) ) ==Example Usage== brun '(a (q 2 4 (c 2 (c 5 (c 11 ())))) (c (q (a (i (= 11 ()) (q . 5) (q 2 4 (c 2 (c 11 (c (a 6 (c 2 (c 5 (c 11 ())))) ()))))) 1) 6 (divmod 5 11)) 1))' '(99...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Return to: Chialisp
Return to: Recursive Functions
(mod (num1 num2)
    (defun remainder (x y)
     (r (divmod x y)))
    (defun gcd (num1 num2)
      (if (= num2 0)
          num1
          (gcd num2 (remainder num1 num2))))
  (gcd num1 num2)
  )

Example Usage

brun '(a (q 2 4 (c 2 (c 5 (c 11 ())))) (c (q (a (i (= 11 ()) (q . 5) (q 2 4 (c 2 (c 11 (c (a 6 (c 2 (c 5 (c 11 ())))) ()))))) 1) 6 (divmod 5 11)) 1))' '(99 33)'

33

brun '(a (q 2 4 (c 2 (c 5 (c 11 ())))) (c (q (a (i (= 11 ()) (q . 5) (q 2 4 (c 2 (c 11 (c (a 6 (c 2 (c 5 (c 11 ())))) ()))))) 1) 6 (divmod 5 11)) 1))' '(206 40)'

2