Created
February 24, 2012 16:21
-
-
Save calebphillips/1901853 to your computer and use it in GitHub Desktop.
Project Euler Problem 35
This file contains hidden or 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
| (ns euler.level2.problem035 | |
| (:use [clojure.contrib.lazy-seqs :only [primes]] | |
| [euler.common :only [prime? parse-int]] )) | |
| (defn rotate [[h & t]] | |
| (apply str (concat t [h]))) | |
| (defn rotations [s] | |
| (take (count s) (iterate rotate s))) | |
| (defn circular? [n] | |
| (every? prime? | |
| (map parse-int | |
| (rotations (str n))))) | |
| (defn euler-35 | |
| "Returns the number of circurlar primes less than n" | |
| [n] | |
| (count | |
| (filter circular? | |
| (take-while #(< % n) primes)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment