Skip to content

Commit 5b3d557

Browse files
author
snh-clj collab
committed
Committing meetup4 collab-2016-07 solutions.
1 parent c44c5f1 commit 5b3d557

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

collab-2016-07/meetup4/src/sn/core.clj

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
99
Write a function which returns the first X fibonacci numbers."
1010
[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)))))))))
1217

1318
(defn four-clojure-30
1419
"http://www.4clojure.com/problem/30 -- Compress a Sequence
@@ -20,6 +25,19 @@
2025
[coll]
2126
::no-implementation)
2227

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+
2341
(defn four-clojure-53
2442
"http://www.4clojure.com/problem/53 -- Longest Increasing Sub-Seq
2543
@@ -31,7 +49,12 @@
3149
same length, use the one that occurs first. An increasing
3250
sub-sequence must have a length of 2 or greater to qualify."
3351
[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+
[]))
3558

3659
(defn four-clojure-54
3760
"http://www.4clojure.com/problem/54 -- Partition a Sequence
@@ -42,7 +65,8 @@
4265
Write a function which returns a sequence of lists of x items
4366
each. Lists of less than x items should not be returned."
4467
[x coll]
45-
::no-implementation)
68+
69+
(filter #(>= (count %) x) (partition x coll)))
4670

4771
(defn four-clojure-60
4872
"http://www.4clojure.com/problem/60 -- Sequence Reductions

0 commit comments

Comments
 (0)