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 minmax-1 [seq] | |
(loop [[a & more] seq | |
min a | |
max a] | |
(if a | |
(recur more (if (< a min) a min) (if (> a max) a max)) | |
{:min min :max max}))) | |
(defn minmax-2 [[n & seq]] | |
(into {} (reduce |
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-time | |
"Use this output to generate timings for the 3 functions above." | |
[f n] | |
(dotimes [i n] | |
(time (f (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
(defn minmax-1 [seq] | |
(loop [[a & more] seq | |
min a | |
max a] | |
(if a | |
(recur more (min a min) (max a max)) | |
{:min min :max max}))) | |
(defn minmax-2 [[n & seq]] | |
(into {} (reduce |
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
java -version | |
java version "1.6.0_25" | |
Java(TM) SE Runtime Environment (build 1.6.0_25-b06) | |
Java HotSpot(TM) 64-Bit Server VM (build 20.0-b11, mixed mode) |
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 strongest-paths | |
"Calculates the strength of the strongest path between each pair of | |
candidates." | |
[defeats candidates] | |
(let [p (into {} (doall (for [i candidates, | |
j candidates :when (not= i j)] | |
(if (> (defeats [i j]) (defeats [j i])) | |
{[i j] (defeats [i j])} | |
{[i j] 0}))))] | |
(println p) |
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 strongest-paths | |
"Calculates the strength of the strongest path between each pair of | |
candidates." | |
[defeats candidates] | |
(let [p (into {} (doall (for [i candidates, | |
j candidates :when (not= i j)] | |
(if (> (defeats [i j]) (defeats [j i])) | |
{[i j] (defeats [i j])} | |
{[i j] 0}))))] | |
(println p) |
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
(let [f (partial * 2)] | |
(map #(%1 %2) (cycle [f identity]) [1 2 3 4 5 6])) | |
; ==> (2 2 6 4 10 6) |
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> (hash (byte-array 3 (map byte [1 2 3]))) | |
391901279 | |
user> (hash (byte-array 3 (map byte [1 2 3]))) | |
568055061 | |
user> (Arrays/hashCode (byte-array 3 (map byte [1 2 3]))) | |
30817 | |
user> (Arrays/hashCode (byte-array 3 (map byte [1 2 3]))) | |
30817 |
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
(def *sessions* | |
^{:private true} | |
(ref {})) ; session-id :-> session | |
(definline get-sessions | |
[] | |
@*sessions*) |
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 enlive-demo.core | |
(:require [net.cgrand | |
[enlive-html :as enlive]])) | |
(defn odd-li | |
[content] | |
(assoc {:tag :li.odd} :content content)) | |
(defn even-li | |
[content] |
OlderNewer