Skip to content
Open
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
7 changes: 7 additions & 0 deletions 2 - Recursion/1 - Computing the GCD/fabriciorby.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(defn gcd [x y]
(cond
(zero? (rem y x)) x
(> x y) (recur (- x y) y)
:else (recur (rem y x) x)))

(println (apply gcd (map read-string (re-seq #"\d+" (read-line)))))
10 changes: 10 additions & 0 deletions 2 - Recursion/2 - Fibonacci Numbers/fabriciorby.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(defn fib
([n] (fib n 0 1))
([n a b]
(case n
0 a
1 a
2 b
(recur (dec n) b (+ a b)))))

(println (fib (read-string (read-line))))
8 changes: 8 additions & 0 deletions 2 - Recursion/3 - Pascal's Triangle/fabriciorby.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(defn pascal-triangle
([n] (pascal-triangle n [1]))
([n acc]
(when (> n 0)
(println (apply str (interpose " " acc)))
(recur (dec n) (mapv + (conj acc 0) (rseq (conj acc 0)))))))

(pascal-triangle (read-string (read-line)))
3 changes: 3 additions & 0 deletions 2 - Recursion/5 - String Mingling/fabriciorby.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(->> (interleave (read-line) (read-line))
(apply str)
(println))
7 changes: 7 additions & 0 deletions 2 - Recursion/6 - String-o-Permute/fabriciorby.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
(defn o-permute [string] (->> (partition 2 2 string)
(mapcat reverse)
(apply str)
(println)))

(->> (repeatedly (read-string (read-line)) #(o-permute (read-line)))
(doall))