Skip to content

Instantly share code, notes, and snippets.

@ponkore
Created April 3, 2012 01:04
Show Gist options
  • Save ponkore/2288478 to your computer and use it in GitHub Desktop.
Save ponkore/2288478 to your computer and use it in GitHub Desktop.
ユークリッド互除法による最大公約数
;; mod を普通に使う
(defn gcd [m n]
(if (zero? n) m
(gcd n (mod m n))))
(gcd 1763 1927)
; => 41
;; mod を使わず引き算だけで求める
(defn gcd [a b]
(cond (= a b) a
(> a b) (gcd (- a b) b)
:else (gcd a (- b a))))
(gcd 1763 1927)
; => 41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment