This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; lein settings | |
| (defproject foo "1.0.0-SNAPSHOT" | |
| :description "Test App" | |
| :dependencies [[com.datomic/datomic "0.1.2678"] | |
| [frinj "0.1.2" :exclusions [org.clojure/clojure]]]) | |
| ;; load libs | |
| (use 'frinj.core 'frinj.calc) | |
| (frinj-init!) | |
| (use '[datomic.api :only (q db) :as d]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| user=> (use 'frinj.repl) | |
| user=> (str (fj 10 :thousand :SEK :to :GBP)) ;; standard currency conversion | |
| "937.1075201531269 [dimensionless]" | |
| user=> (str (fj :Gold :per :Silver)) ;; Gold vs Silver price | |
| "49.95612708018155 [dimensionless]" | |
| user=> (str (fj :Milk)) | |
| "0.3659673552268969 dollar kg^-1 [price_per_mass]" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns nqueens-cl | |
| (:refer-clojure :exclude [==]) | |
| (:use [clojure.core.logic])) | |
| (defmacro def-subo | |
| "Generate subtraction algebra" | |
| [name n] | |
| (let [xn 'x, yn 'y, rn 'r | |
| gen-association (fn [x y] | |
| `[(== ~xn ~x) (== ~yn ~y) (== ~rn ~(- x y))]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn prime? [x] | |
| (let [divs (range 2 (inc (int (Math/sqrt x)))) | |
| rems (map #(rem x %) divs)] | |
| (not (some zero? rems)))) | |
| (filter prime? (range 1000)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn fib [n] | |
| (loop [back1 1, back2 0, n n] | |
| (cond | |
| (= n 0) 0 | |
| (= n 1) (+ back1 back2) | |
| :else (recur back2 (+ back1 back2) (- n 1))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn pascals-trapezoid [v] | |
| (iterate #(map + `(0 ~@%) `(~@% 0)) v)) | |
| (take 10 (pascals-trapezoid [1])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn my-part [n col] | |
| (when-not (empty? col) | |
| (lazy-seq (cons (take n col) (my-part n (drop n col)))))) | |
| (->> | |
| (iterate inc 1) | |
| (my-part 4) | |
| (drop 55) | |
| (take 10)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn get-anagram-map | |
| "map of words keyed by letter-sorted 'words' (which all anagrams share)" | |
| [dict] | |
| (reduce (fn [acc w] | |
| (let [sw (apply str (sort w))] | |
| (if-let [d (get acc sw)] | |
| (assoc acc sw (conj d w)) | |
| (assoc acc sw (list w))))) {} dict)) | |
| (defn knuth-anagrams |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; olabini: Am I blind. Clojure doesn't have a tee-style combinator that allow you to chain side effecting functions without threading values? | |
| (defn tee [& fs] (comp last (apply juxt fs))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defproject zguide "1.0.0-SNAPSHOT" | |
| :source-path "../Clojure/" | |
| :description "0MQ zguide in Clojure" | |
| :dependencies [[org.clojure/clojure "1.4.0"] | |
| [org.zmq/zmq "1.0.0"] | |
| ]) |