File tree Expand file tree Collapse file tree 1 file changed +27
-3
lines changed
collab-2016-07/meetup4/src/sn Expand file tree Collapse file tree 1 file changed +27
-3
lines changed Original file line number Diff line number Diff line change 8
8
9
9
Write a function which returns the first X fibonacci numbers."
10
10
[x]
11
- ::no-implementation )
11
+ (loop [cnt x s []]
12
+ (if (zero? cnt)
13
+ s
14
+ (cond (empty? s) (recur (dec cnt) [1 ])
15
+ (= (count s) 1 ) (recur (dec cnt) [1 1 ])
16
+ :else (recur (dec cnt) (conj s (+ (last s) (nth s (- (count s) 2 )))))))))
12
17
13
18
(defn four-clojure-30
14
19
" http://www.4clojure.com/problem/30 -- Compress a Sequence
20
25
[coll]
21
26
::no-implementation )
22
27
28
+ (defn incsub
29
+ [[outseq curseq] n]
30
+ #_ (println " outseq:" outseq " curseq:" curseq)
31
+ (cond (empty? curseq) [outseq [n]]
32
+ (> n (last curseq)) [outseq (conj curseq n)]
33
+ :else [(conj outseq curseq) [n]]))
34
+
35
+ (defn maxlencoll
36
+ [existing new]
37
+ (if (> (count new) (count existing))
38
+ new
39
+ existing))
40
+
23
41
(defn four-clojure-53
24
42
" http://www.4clojure.com/problem/53 -- Longest Increasing Sub-Seq
25
43
31
49
same length, use the one that occurs first. An increasing
32
50
sub-sequence must have a length of 2 or greater to qualify."
33
51
[coll]
34
- ::no-implementation )
52
+ (reduce maxlencoll
53
+ (first
54
+ (filter #(>= (count %) 2 )
55
+ (let [[l r] (reduce incsub [[] []] coll)]
56
+ (conj l r))))
57
+ []))
35
58
36
59
(defn four-clojure-54
37
60
" http://www.4clojure.com/problem/54 -- Partition a Sequence
42
65
Write a function which returns a sequence of lists of x items
43
66
each. Lists of less than x items should not be returned."
44
67
[x coll]
45
- ::no-implementation )
68
+
69
+ (filter #(>= (count %) x) (partition x coll)))
46
70
47
71
(defn four-clojure-60
48
72
" http://www.4clojure.com/problem/60 -- Sequence Reductions
You can’t perform that action at this time.
0 commit comments