This file contains 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
package akka.tutorial.first.java; | |
import akka.actor.ActorRef; | |
import akka.actor.UntypedActor; | |
import akka.actor.UntypedActorFactory; | |
import akka.actor.ActorSystem; | |
import akka.actor.Props; | |
public class Hello { | |
This file contains 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"] | |
]) |
This file contains 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 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 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 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 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 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 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 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]" |