-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob-060.clj
30 lines (26 loc) · 929 Bytes
/
prob-060.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
;;;;;;;;;; problem 060 ;;;;;;;;;;
(use '[clojure.contrib.lazy-seqs :only (primes)]
'[clojure.contrib.def :only (defvar)]
'[clojure.euler.helpers :only (prime?)])
(defn concat-prime? [ab]
(let [a (str (first ab))
b (str (last ab))
n1 (Integer. (str a b))
n2 (Integer. (str b a))]
(and (prime? n1) (prime? n2))))
(defn all-concat-prime? [n ps]
(every? concat-prime? (partition 2 (interleave ps (repeat n)))))
(defvar prime-combos
(let [ps (rest (take-while #(< % 10000) primes))]
(for [a ps
b (filter #(> % a) ps)
:when (all-concat-prime? b [a])
c (filter #(> % b) ps)
:when (all-concat-prime? c [a b])
d (filter #(> % c) ps)
:when (all-concat-prime? d [a b c])
e (filter #(> % d) ps)
:when (all-concat-prime? e [a b c d])]
[a b c d e])))
(defn prob-060 []
(reduce + (first prime-combos)))