Some further changes yet.
Paragraphs are separated by a blank line.
2nd paragraph. Italic, bold, and monospace
. Itemized lists
look like:
(defn map- [f coll] | |
(lazy-seq (cons (f (first coll)) (map- f (rest coll))))) |
unreadable message: (:emacs-rex (swank:listener-eval "(println \"â\") | |
") "user" :repl-thread 6 | |
exception in read loop | |
java.lang.RuntimeException: java.lang.Exception: EOF while reading | |
at clojure.lang.RT.readString(RT.java:1263) | |
at clojure.core$read_string.invoke(core.clj:2897) | |
at swank.core.protocol$read_swank_message$fn__240.invoke(protocol.clj:44) | |
at swank.core.protocol$read_swank_message.invoke(protocol.clj:43) | |
at swank.core.connection$read_from_connection.invoke(connection.clj:59) | |
at swank.core$read_loop.invoke(core.clj:337) |
(defn gen-prefn | |
"Generates a function that for input q returns the lengths of the longest | |
prefix of pattern that is also a suffix of pattern[1..q]." | |
[pattern] | |
(let [pattern (vec pattern) | |
add-entry (fn [[pfn l] q] | |
(if (= (pattern l) (pattern q)) | |
[(conj pfn [(inc q) (inc l)]) (inc l)] | |
(if (zero? l) | |
[(conj pfn [(inc q) 0]) 0] |
(defrecord DirectedGraph [vertices edges weights] | |
;; A directed graph: 'vertices' is a sorted set of vertices, 'edges' is a map | |
;; from vertices to a sorted set of adjacent vertices, 'weights' is a map from | |
;; edges given as vertex tuple [from to] to weights. | |
Graph | |
(set-vertex [_ v] | |
(DirectedGraph. (conj vertices v) | |
(conj edges [v (sorted-set)]) | |
weights)) | |
(set-edge [this edge] |
(defprotocol Graph | |
(set-vertex [this v]) | |
(set-edge [this from to] | |
[this from to weight])) | |
(defrecord DirectedGraph [vs em wm] | |
;; A directed graph: vs is a sorted set of vertices, em is a map from vertices | |
;; to a sorted set of adjacent vertices, wm is a map from edges given as | |
;; vertex tuple [from to] to weights. | |
Graph |
(defn deinterleave | |
[coll n] | |
(->> | |
(loop [out [(take n coll)] | |
tail (drop n coll)] | |
(if (seq tail) | |
(recur (conj out (take n tail)) (drop n tail)) | |
out)) | |
(apply map vector))) |
(defn find-path | |
[graph from to] | |
((fn this [graph from to path] | |
(if (= from to) | |
(println "Found it:" path) | |
(let [children (for [v (graph from) :when (not (some #{v} path))] v)] | |
(if (empty? children) | |
(println "Dead end:" path) | |
(doseq [v children] | |
(this graph v to (conj path v))))))) |
(defn mult? | |
"Returns true iff n is a multiple of one of the numbers in coll." | |
[coll n] | |
(some #(zero? (rem n %)) coll)) | |
(def primes | |
(letfn [(rest-primes | |
[known-primes] | |
(lazy-seq | |
(let [highest-known-prime (peek known-primes), |
(def pattern-graph | |
[[0 1 0 1 1 1 0 1 0] | |
[1 0 1 1 1 1 1 0 1] | |
[0 1 0 1 1 1 0 1 0] | |
[1 1 1 0 1 0 1 1 1] | |
[1 1 1 1 0 1 1 1 1] | |
[1 1 1 0 1 0 1 1 1] | |
[0 1 0 1 1 1 0 1 0] | |
[1 0 1 1 1 1 1 0 1] | |
[0 1 0 1 1 1 0 1 0]]) |