-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprob-061.clj
54 lines (49 loc) · 2.32 KB
/
prob-061.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;;;;;;;;;; problem 061 ;;;;;;;;;;
(use '[clojure.euler.helpers :only (triangle? square? pentagonal? hexagonal?
heptagonal? octagonal?)])
(defn from-cyclical [n]
(Integer. (str (subs (str n) 2) "00")))
(defn to-cyclical [n]
(inc (Integer. (str (subs (str n) 2) "99"))))
(defn to-type [n]
(filter #(not (nil? %)) [(when (triangle? n) :triangle)
(when (square? n) :square)
(when (pentagonal? n) :pentagonal)
(when (hexagonal? n) :hexagonal)
(when (heptagonal? n) :heptagonal)
(when (octagonal? n) :octagonal)]))
(defn valid-coll? [c]
(= (count c) (count (set c))))
(defn prob-061 []
(reduce + (first
(for [a (range 1000 10000)
:let [at (to-type a)]
:when (and (not-empty at) (valid-coll? [at]))
:let [from (from-cyclical a) to (to-cyclical a)]
:when (> from 999)
b (range from to)
:let [bt (to-type b)]
:when (and (not-empty bt) (valid-coll? [at bt]))
:let [from (from-cyclical b) to (to-cyclical b)]
:when (> from 999)
c (range from to)
:let [ct (to-type c)]
:when (and (not-empty ct) (valid-coll? [at bt ct]))
:let [from (from-cyclical c) to (to-cyclical c)]
:when (> from 999)
d (range from to)
:let [dt (to-type d)]
:when (and (not-empty dt) (valid-coll? [at bt ct dt]))
:let [from (from-cyclical d) to (to-cyclical d)]
:when (> from 999)
e (range from to)
:let [et (to-type e)]
:when (and (not-empty et) (valid-coll? [at bt ct dt et]))
:let [from (from-cyclical e) to (to-cyclical e)]
:when (> from 999)
f (range from to)
:let [ft (to-type f)]
:when (and (not-empty ft) (valid-coll? [at bt ct dt et ft]))
:let [from (from-cyclical f) to (to-cyclical f)]
:when (<= from a to)]
[a b c d e f]))))