Skip to content
This repository was archived by the owner on Sep 7, 2025. It is now read-only.

Commit 94b8c61

Browse files
authored
Merge pull request #5 from michellymenezes/quick-sort
Quick sort
2 parents 0ab68f8 + c91ec73 commit 94b8c61

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

math/quadratic_equation.clj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(ns math/quadratic-equation)
2+
3+
(defn calculate-delta
4+
[a b c]
5+
(- (* b b) (* 4 a c)))
6+
7+
(defn calculate-x [delta a b]
8+
(conj #{} (-> b - (+ (Math/sqrt delta)) (/ (* 2 a)))
9+
(-> b - (- (Math/sqrt delta)) (/ (* 2 a)))))
10+
11+
(defn quadratic-equation [a b c]
12+
(let [delta (calculate-delta a b c)]
13+
(when (>= delta 0)
14+
(calculate-x delta a b))))

sorting/quick_sort.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(ns sorting.quick-sort)
2+
3+
(defn quick-sort
4+
[[head & tail :as values]]
5+
(if (empty? values)
6+
[]
7+
(let [greaters (filter #(> % head) tail)
8+
smallers (filter #(<= % head) tail)]
9+
(concat (quick-sort smallers) [head] (quick-sort greaters)))))

0 commit comments

Comments
 (0)