Skip to content

Instantly share code, notes, and snippets.

@calebphillips
Created February 24, 2012 16:21
Show Gist options
  • Select an option

  • Save calebphillips/1901853 to your computer and use it in GitHub Desktop.

Select an option

Save calebphillips/1901853 to your computer and use it in GitHub Desktop.
Project Euler Problem 35
(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