Commits

Victor Iacoban committed 5a6b5a7

34 35

Comments (0)

Files changed (4)

 
 .idea
 *.iml
-
-
+*.ipr
+*.iws
+.gradle
+buildscript {
+  repositories {
+    mavenRepo name: 'clojars', url: 'http://clojars.org/repo'
+  }
+  dependencies {
+    classpath 'clojuresque:clojuresque:1.5.+'
+  }
+}
+
+apply plugin: 'clojure'
+apply plugin: 'idea'
+
+repositories {
+  mavenCentral()
+  clojarsRepo()
+}
+
+dependencies {
+  compile 'org.clojure:clojure:1.4.0'
+  compile 'org.clojure:math.combinatorics:0.0.3'
+}

src/main/clojure/euler/level02/prob034.clj

-(ns euler.level02.prob034)
+(ns euler.level02.prob034
+  (:use tools.factorial))
+
+(defn get-limit []
+  (let [dm (factorial 9)]
+    (Math/pow 10 (inc (first (reverse (take-while #(> (* % dm) (Math/pow 10 %)) (range 1 10))))))))
+
+(defn good? [n]
+  (= (bigdec n) (reduce + (map #(factorial (read-string (str %))) (str n)))))
 
 (defn euler34 []
-  )
+  (let [l (get-limit)]
+    (reduce + (for [x (range 3 l) :when (good? x)] x))))

src/main/clojure/euler/level02/prob035.clj

+(ns euler.level02.prob035
+  (:use tools.primes))
+
+(defn rotations [s]
+  (map #(concat (second %) (first %)) (map #(split-at % s) (range 1 (count s)))))
+
+(defn euler35 [n]
+  (let [primes-as-sets (into #{} (map #(vec (str %)) (take-while (partial >= n) (primes-seq))))]
+    (count (filter #(every? primes-as-sets (map vec (rotations %))) primes-as-sets))))