Last active
August 29, 2015 14:01
-
-
Save muratamuu/e29c553e6a4db50870c6 to your computer and use it in GitHub Desktop.
Project Eularの Problem 3 のプログラム (Clojure版)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Answer of Eular Problem 3 "Largest prime factor" | |
(defn primes [] | |
(letfn | |
[(primes [p ns] | |
(let [ns (filter #(not= (rem % p) 0) ns)] | |
(lazy-seq (cons p (primes (first ns) ns)))))] | |
(primes 2 (iterate inc 2)))) | |
(defn largePrimeFactorOf [x] | |
(loop [primes (primes) x x] | |
(let [p (first primes)] | |
(if (= (rem x p) 0) | |
(if (= (quot x p) 1) | |
p | |
(recur primes (quot x p))) | |
(recur (rest primes) x))))) | |
(defn answer [] (largePrimeFactorOf 600851475143)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment