Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

done #511

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

done #511

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject one-function-to-rule-them-all "1.0.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]
:dependencies [[org.clojure/clojure "1.8.0"]
[iloveponies.tests/one-function-to-rule-them-all "0.1.0-SNAPSHOT"]]
:profiles {:dev {:plugins [[lein-midje "3.1.1"]]}})
107 changes: 88 additions & 19 deletions src/one_function_to_rule_them_all.clj
Original file line number Diff line number Diff line change
@@ -1,43 +1,112 @@
(ns one-function-to-rule-them-all)

(defn concat-elements [a-seq]
:-)
(reduce concat [] a-seq))

(defn str-cat [a-seq]
:-)
(let [helper (fn [f r]
(str f " " r))]
(if (empty? a-seq)
""
(reduce helper a-seq))))


(defn my-interpose [x a-seq]
[:-])
(let [helper (fn [f r]
(conj f x r))]
(if (empty? a-seq)
[]
(drop 1 (reduce helper [] a-seq)))))



(defn my-count [a-seq]
:-)
(let [counter (fn [count e]
(inc count))]
(reduce counter 0 a-seq)))

(defn my-reverse [a-seq]
[:-])
(let [helper (fn [f r]
(cons r f))]
(reduce helper [] a-seq)))

(defn min-max-element [a-seq]
[:-])
(reduce (fn [[mi ma] e]
[(min mi e) (max ma e)])
[(first a-seq) (first a-seq)]
a-seq))




(defn insert [sorted-seq n]
[:-])
(loop [b []
r sorted-seq]
(cond
(empty? r) (conj b n)
(<= n (first r)) (into (conj b n (first r)) (rest r))
:else (recur (conj b (first r)) (rest r)))))





(defn insertion-sort [a-seq]
[:-])
(reduce insert [] a-seq))


(defn toggle [a-set elem]
(if (contains? a-set elem)
(disj a-set elem)
(conj a-set elem)))

(defn parity [a-seq]
[:-])
(reduce toggle #{} a-seq))

(defn minus
([x] (- x))
([x y] (- x y)))


(defn count-params
([] 0)
([x & more]
(let [helper (fn [c e]
(inc c))]
(reduce helper (helper 0 x) more))))


(defn my-*
([] 1)
([x] x)
([x y] (* x y))
([x y & more] (reduce my-*(my-* x y) more)))

(defn pred-and
([] (fn [x] true))
([pred1](fn [x] (pred1 x)))
([pred1 pred2] (fn [x] (and (pred1 x) (pred2 x))))
([pred1 pred2 & more] (reduce pred-and (pred-and pred1 pred2) more)))

(defn minus [x]
:-)

(defn count-params [x]
:-)
(defn transpose [matrix]
(partition (count matrix) (into [] (for [i (range 0 (count (first matrix)))
j (range 0 (count matrix))]

(get-in matrix [j i])))))



(defn my-* [x]
:-)

(defn pred-and [x]
(fn [x] :-))
(defn my-map
([f a-seq] (reduce (fn [new e]
(conj new (f e)))
[]
a-seq))
([f a-seq & more]
(let [trans (transpose (into [] (concat [a-seq] more)))]
(my-map #(apply f %) trans))))

(defn my-map [f a-seq]
[:-])