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

solutions, all but encore #513

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
82 changes: 64 additions & 18 deletions src/one_function_to_rule_them_all.clj
Original file line number Diff line number Diff line change
@@ -1,43 +1,89 @@
(ns one-function-to-rule-them-all)

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

(defn str-cat [a-seq]
:-)
"Teht2"
(if (empty? a-seq)
""
;http://clojure.github.io/clojure/clojure.string-api.html#clojure.string/join
(reduce #(clojure.string/join [%1 " " %2]) a-seq)))

(defn my-interpose [x a-seq]
[:-])
"Teht3"
(interpose x a-seq))

(defn my-count [a-seq]
:-)
"Teht4"
(if (empty? a-seq) 0
(+ 1 (my-count (rest a-seq)))))

(defn my-reverse [a-seq]
[:-])
"Teht5"
(if (empty? a-seq)
[]
(conj (my-reverse (rest a-seq)) (first a-seq) )))

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

(defn insert [sorted-seq n]
[:-])
"Teht7"
;http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/split-with
(let [[smaller-ones bigger-ones] (split-with #(< % n) sorted-seq)]
(concat smaller-ones [n] bigger-ones)))

(defn insertion-sort [a-seq]
[:-])
"Teht7"
(loop [list a-seq result '()]
(if (empty? list) result
(recur (rest list) (insert result (first list))))))

(defn parity [a-seq]
[:-])
"Teht8"
(set
;http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/keep
(keep
(fn [[element occurences]]
;https://clojuredocs.org/clojure.core/when
(when (odd? occurences) element))
;http://clojure.github.io/clojure/clojure.core-api.html#clojure.core/frequencies
(frequencies a-seq))))

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

(defn count-params [x]
:-)
(defn count-params
"Teht10"
([] 0)
([x] 1)
([x y] 2)
([x y & the-rest]
(+ (count the-rest) 2)))

(defn my-* [x]
:-)
(defn my-*
"Teht11"
([] 1)
([x] x)
([x y] (* x y))
([x y & the-rest]
(* x y (reduce * the-rest))))

(defn pred-and [x]
(fn [x] :-))
(defn pred-and
"Teht12"
([] (fn [x] true))
([pred1]
(fn [x] (pred1 x)))
([pred1 pred2]
(fn [x] (and (pred1 x) (pred2 x))))
([pred1 pred2 & the-rest]
(reduce pred-and (pred-and pred1 pred2) the-rest)))

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