Skip to content

Commit

Permalink
backup
Browse files Browse the repository at this point in the history
  • Loading branch information
samitsal committed Oct 26, 2013
1 parent bbb7272 commit be95b2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .nrepl-port
Original file line number Diff line number Diff line change
@@ -1 +1 @@
59918
53915
26 changes: 21 additions & 5 deletions src/recursion.clj
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,6 @@
;(my-frequencies-helper a-seq))
)



;(my-frequencies [:a "moi" :a "moi" "moi" :a 1]) ;=> {:a 3, "moi" 3, 1 1}

(defn un-frequencies [a-map]
Expand All @@ -229,17 +227,33 @@
(defn halve [a-seq]
(vector (my-take (int (/ (count a-seq) 2)) a-seq) (my-drop (/ (count a-seq) 2) a-seq)))

;(halve [1 2 3 4]) ;=> [(1 2) (3 4)]
;(halve [1 2 3]) ;=> [(1 2) (3 4)]
;(halve [1 2 3 4 5]) ;=> [(1 2) (3 4 5)]
;(halve [1]) ;=> [() (1)]

;(concat [1 2 3] [4])

(defn seq-merge [a-seq b-seq]
)
(if (empty? a-seq) b-seq
(if (< (first a-seq) (first b-seq)) (cons (first a-seq) (seq-merge (rest a-seq) b-seq))
(cons (first b-seq) (seq-merge a-seq (rest b-seq))))
))

;(seq-merge [4] [1 2 6 7]) ;=> (1 2 4 6 7)
;(seq-merge [1 5 7 9] [2 2 8 10]) ;=> (1 2 2 5 7 8 9 10)
;(seq-merge [1 3] [100 4])

(defn merge-sort [a-seq]
[:-])
(if (empty? a-seq)
'()
(if (singleton? a-seq)
a-seq
(let [[a b] (halve a-seq)]
(seq-merge (merge-sort a)(merge-sort b))))))

;(merge-sort []) ;=> ()
;(merge-sort [1 2 3]) ;=> (1 2 3)
;(merge-sort [5 3 4 17 2 100 1]) ;=> (1 2 3 4 5 17 100)

(defn split-into-monotonics [a-seq]
[:-])
Expand All @@ -258,4 +272,6 @@





Expand Down

0 comments on commit be95b2e

Please sign in to comment.