Skip to content

Instantly share code, notes, and snippets.

(def second (fn [list] (nth list 1) ))
(def square (fn [n] (n * n)))
(def sum (fn [list] (apply + list)))
(def add-square (fn [list] (sum (map square list)) ))
(def fac (fn [n] (apply * (range 1 (+ n 1) ))))
(def fatorialT
(fn [n acc]
(if (= n 0)
acc
(fatorialT (dec n) (* acc n)))))
(prn (fatorialT 5 1))
(def rec
(fn [n acc]
(if (empty? n)
acc
(recur (rest n) (+ acc (first n))))))
(prn (rec [4 3 2 1] 0))
(def rec
(fn [f numbers acc]
(if (empty? numbers)
acc
(recur f (rest numbers) (f acc (first numbers))))))
(prn (rec * [4 2 3] 1 ))
(defn x [map key]
(conj map {key (count map)}))
(defn rec [f numbers acc]
(if (empty? numbers)
acc
(recur f (rest numbers) (f acc (first numbers)))))
(prn (rec x [:a :b :c] {} ))
@renanreismartins
renanreismartins / ->.clj
Created October 29, 2014 06:59
-> operator exe 4
(+ (* (+ 1 2) 3) 4)
(-> (+ 1 2) (* 3) (+ 4))
@renanreismartins
renanreismartins / manhattan-distance.clj
Last active August 29, 2015 14:11
manhattan distance
(use 'clojure.set)
(use 'clojure.math.numeric-tower)
(def data
{:Hailey {"Broken Bells" 4,
"Deadmau5" 1,
"Norah Jones" 4,
"The Strokes" 4,
"Vampire Weekend" 1}
(use 'clojure.set)
(def data
{:Hailey {"Broken Bells" 4,
"Deadmau5" 1,
"Norah Jones" 4,
"The Strokes" 4,
"Vampire Weekend" 1}
:Veronica {"Blues Traveler" 3,