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 #518

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

done #518

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
65 changes: 47 additions & 18 deletions src/one_function_to_rule_them_all.clj
Original file line number Diff line number Diff line change
@@ -1,43 +1,72 @@
(ns one-function-to-rule-them-all)

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

(defn str-cat [a-seq]
:-)
(if (empty? a-seq) ""
(reduce (fn [a b] (str a " " b)) a-seq)))

(defn my-interpose [x a-seq]
[:-])
(if (empty? a-seq)
()
(reduce (fn [a-sequence an-item] (if (or (== (count a-sequence) (* 2 (count a-seq))) (empty? a-sequence))
(concat a-sequence [an-item])
(concat a-sequence [x] [an-item]))) [] a-seq)))

(defn my-count [a-seq]
:-)
(reduce (fn [acc next-element] (inc acc)) 0 a-seq))

(defn my-reverse [a-seq]
[:-])
(reduce (fn [a b]
(conj a b))
() a-seq))

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

(defn insert [sorted-seq n]
[:-])
(loop [result [] a-seq sorted-seq]
(cond
(empty? a-seq)
(conj result n)
(<= n (first a-seq))
(concat (conj result n) a-seq)
:else (recur (conj result (first a-seq)) (rest a-seq)))))

(defn insertion-sort [a-seq]
[:-])
(loop [sorted-sequence () a-sequence a-seq]
(cond
(empty? a-sequence)
sorted-sequence
:else (recur (insert (vec sorted-sequence) (first a-sequence)) (rest a-sequence)))))

(defn parity [a-seq]
[:-])
(reduce (fn [a-set b]
(if (contains? a-set b)
(disj a-set b)
(conj a-set b)))
#{} a-seq))

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

(defn count-params [x]
:-)
(defn count-params
([& more] (count more)))

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

(defn pred-and [x]
(fn [x] :-))
(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 my-map [f a-seq]
[:-])
[:-])