Skip to content

Commit

Permalink
some done
Browse files Browse the repository at this point in the history
  • Loading branch information
samitsal committed Oct 23, 2013
1 parent 3c3519c commit 680655c
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 92 deletions.
1 change: 1 addition & 0 deletions .nrepl-port
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
62004
212 changes: 120 additions & 92 deletions src/recursion.clj
Original file line number Diff line number Diff line change
@@ -1,92 +1,120 @@
(ns recursion)

(defn product [coll]
:-)

(defn singleton? [coll]
:-)

(defn my-last [coll]
:-)

(defn max-element [a-seq]
:-)

(defn seq-max [seq-1 seq-2]
[:-])

(defn longest-sequence [a-seq]
[:-])

(defn my-filter [pred? a-seq]
[:-])

(defn sequence-contains? [elem a-seq]
:-)

(defn my-take-while [pred? a-seq]
[:-])

(defn my-drop-while [pred? a-seq]
[:-])

(defn seq= [a-seq b-seq]
:-)

(defn my-map [f seq-1 seq-2]
[:-])

(defn power [n k]
:-)

(defn fib [n]
:-)

(defn my-repeat [how-many-times what-to-repeat]
[:-])

(defn my-range [up-to]
[:-])

(defn tails [a-seq]
[:-])

(defn inits [a-seq]
[:-])

(defn rotations [a-seq]
[:-])

(defn my-frequencies-helper [freqs a-seq]
[:-])

(defn my-frequencies [a-seq]
[:-])

(defn un-frequencies [a-map]
[:-])

(defn my-take [n coll]
[:-])

(defn my-drop [n coll]
[:-])

(defn halve [a-seq]
[:-])

(defn seq-merge [a-seq b-seq]
[:-])

(defn merge-sort [a-seq]
[:-])

(defn split-into-monotonics [a-seq]
[:-])

(defn permutations [a-set]
[:-])

(defn powerset [a-set]
[:-])

(ns recursion)

(defn product [coll]
(if (empty? coll)
0
(* (first coll)
(product (rest coll)))))

; The if acts as our base case, otherwise the function
; will recursively call itself.

(defn singleton? [coll]
(if (not (nil? (first coll))) (nil? (first (rest coll))) false) )

;(singleton? [1]) ;=> true
;(singleton? #{2}) ;=> true
;(singleton? []) ;=> false
;(singleton? [1 2 3]) ;=> false

(defn my-last [coll]
(if (not (nil? (first (rest coll)))) (my-last (rest coll)) (first coll)))

;(my-last []) ;=> nil
;(my-last [1 2 3]) ;=> 3
;(my-last [2 5]) ;=> 5

(defn max-element [a-seq]
(if (not (singleton? a-seq))
(if (< (first a-seq) (last a-seq)) ;truethsy for outer if
(max-element (rest a-seq))
(max-element (butlast a-seq)))
(if (empty? a-seq) nil (first a-seq)))) ;falsy for outer if

;(max-element [2 4 1 4]) ;=> 4
;(max-element [2]) ;=> 2
;(max-element []) ;=> nil

(defn seq-max [seq-1 seq-2]
[:-])

(defn longest-sequence [a-seq]
[:-])

(defn my-filter [pred? a-seq]
[:-])

(defn sequence-contains? [elem a-seq]
:-)

(defn my-take-while [pred? a-seq]
[:-])

(defn my-drop-while [pred? a-seq]
[:-])

(defn seq= [a-seq b-seq]
:-)

(defn my-map [f seq-1 seq-2]
[:-])

(defn power [n k]
:-)

(defn fib [n]
:-)

(defn my-repeat [how-many-times what-to-repeat]
[:-])

(defn my-range [up-to]
[:-])

(defn tails [a-seq]
[:-])

(defn inits [a-seq]
[:-])

(defn rotations [a-seq]
[:-])

(defn my-frequencies-helper [freqs a-seq]
[:-])

(defn my-frequencies [a-seq]
[:-])

(defn un-frequencies [a-map]
[:-])

(defn my-take [n coll]
[:-])

(defn my-drop [n coll]
[:-])

(defn halve [a-seq]
[:-])

(defn seq-merge [a-seq b-seq]
[:-])

(defn merge-sort [a-seq]
[:-])

(defn split-into-monotonics [a-seq]
[:-])

(defn permutations [a-set]
[:-])

(defn powerset [a-set]
[:-])





Expand Down

0 comments on commit 680655c

Please sign in to comment.