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 grid-size 30) | |
;; A collection of walls | |
(def walls (atom #{})) | |
;; The route to the finish | |
(def route (atom #{})) | |
(defstruct point :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
(defn rss-merge | |
"Join together the two feeds specified, using min-date as the selector which grabs the minimum | |
date from the published field" | |
[feed1 feed2] | |
(join-all | |
min-date | |
(get-entries-from-rss feed1) | |
(get-entries-from-rss feed2))) |
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 join-all | |
"Join the lists provided using f to select an element each time" | |
[f & lists] | |
(let [l (remove empty? lists)] | |
(when-not (empty? l) | |
(let [n (reduce f (map first l)) | |
c (count (filter (partial = true) (map (fn [x] (= (first x) n)) l))) | |
r (map (fn [x] (if (= (first x) n) (rest x) x)) l)] | |
(lazy-seq | |
(concat |
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-entries-from-rss | |
"Get a list of entries from an RSS feed" | |
[src] | |
(xm/xml-> (zip/xml-zip (parse-trim src)) :entry)) | |
(defn get-date | |
"Given an RSS entry, get the date" | |
[entry] | |
(xm/xml-> entry :published xm/text)) |
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
(defvar | |
dispatch-table | |
{:single-match | |
{'?is match-is '?or match-or '?and match-and '?not match-not} | |
:segment-match | |
{'?* segment-match '?+ segment-match+ '?? segment-match? '?if match-if}} | |
"Dispatch table") | |
(defn single-match-fn | |
"Get the single-match function for x, if it is a symbol that has one." |
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 match-if | |
"Test an arbitrary expression involving variables." | |
[pattern input bindings] | |
(dbg :patmatch (format "match-if %s %s %s" pattern input bindings)) | |
(let [f (postwalk-replace bindings (second (first pattern)))] | |
(when (eval f) | |
(pat-match (rest pattern) input bindings)))) |
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
;; From http://norvig.com/paip/patmatch.lisp | |
(defun match-if (pattern input bindings) | |
"Test an arbitrary expression involving variables. | |
The pattern looks like ((?if code) . rest)." | |
;; *** fix, rjf 10/1/92 (used to eval binding values) | |
(and (progv (mapcar #'car bindings) | |
(mapcar #'cdr bindings) | |
(eval (second (first pattern)))) | |
(pat-match (rest pattern) input bindings))) |
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 histogram | |
[filename] | |
(reduce | |
(fn [accum x] | |
(let [h (Math/floor (/ x 10))] | |
(assoc accum h (inc (get accum h 0))))) | |
{} | |
(take-nth 2 (drop 1 (read-lines filename))))) |
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 uk.co.fatvat.wave.parrot | |
(:import [com.google.wave.api RobotMessageBundle EventType]) | |
(:gen-class :extends com.google.wave.api.AbstractRobotServlet)) | |
(defn- add-blip | |
[wavelet message] | |
(.append (.getDocument (.appendBlip wavelet)) message)) | |
(defn -processEvents | |
[_ bundle] |
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 solve | |
"Solve a system of equations by constraint propagation" | |
[equations known] | |
(dbg :student (format "SOLVE %s %s" equations known)) | |
(or | |
(some (fn [equation] | |
(let [x (one-unknown equation)] | |
(when x | |
(let [answer (solve-arithmetic (isolate equation x))] | |
(solve (postwalk-replace {(:lhs answer) (:rhs answer)} |