Skip to content

Instantly share code, notes, and snippets.

@ahjones
ahjones / core.clj
Created January 31, 2016 21:46
Solver for a Sokoban like game
(ns sokoban.core
(:require [clojure.data.priority-map :refer [priority-map-keyfn-by]]))
(def test-plan "########\n#@ # a#\n# A # #\n# #\n# #\n########")
(def test-tricky "#######\n##bac #\n#@A #\n###BC #\n### #\n#######")
(def barrels (set "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
(def targets (set "abcdefghijklmnopqrstuvwxyz"))
(def player \@)
(def wall \#)
@ahjones
ahjones / core.clj
Last active January 30, 2016 19:36
Genetic nonogram
(ns non.core)
(def radioactivity 0.001)
(defn board
[cols rows]
(vec (repeat rows
(vec (repeat cols 0)))))
(defn random-board
@ahjones
ahjones / best-authors.txt
Last active December 20, 2015 08:59
The best scifi and fantasy authors as rated by readers of Focus magazine, sorted by frequency of occurrence. http://www.locusmag.com/2012/AllCenturyPollsResults.html
15 Heinlein, Robert A.
13 Le Guin, Ursula K.
12 Asimov, Isaac
11 Gaiman, Neil
10 Zelazny, Roger
9 Chiang, Ted
8 Bradbury, Ray
7 Wolfe, Gene
7 Martin, George R. R.
7 Clarke, Arthur C.
(ns find-errors.core
(:require [clojurewerkz.elastisch.rest :as esr]
[clojurewerkz.elastisch.rest.document :as esd]
[clojurewerkz.elastisch.query :as q]
[clojurewerkz.elastisch.rest.response :as esrsp]))
(defn -main
[& args]
(esr/connect! "http://elasaticsearch:9200")
(let [res
(ns example.core
(:use [compojure.core]
[compojure.handler]))
(defroutes app
(GET "/" [] "Hello World!"))
@ahjones
ahjones / gol.clj
Created November 9, 2012 21:40
Clojure Game of Life
(defn show-line [l]
(apply str (map #(if (= 1 %) \x \space) l)))
(defn show [w]
(str "\n----\n"
(apply str (interpose \newline (map show-line w)))
"\n----\n"))
(defn get-cell [w x y]
(if (and (< -1 x (count (first w)))
@ahjones
ahjones / sort.clj
Created June 13, 2012 21:16
Quicksort with clojure
(ns sort)
(defn qsort [l]
(if (first l)
(concat
(qsort (filter #(< (first l) %) (rest l)))
[(first l)]
(qsort (filter #(>= (first l) %) (rest l))))
()))
@ahjones
ahjones / clojure-rest-driver.clj
Created June 1, 2012 22:41
Rest client driver with Clojure and Midje
(ns logging.web-test
(:use midje.sweet
ring.mock.request
my-thing.web)
(:import [com.github.restdriver.clientdriver
ClientDriverFactory
ClientDriverRule
RestClientDriver]))
(def driver (.. (ClientDriverFactory.) (createClientDriver 8123)))
module Parser where
data Token = Open_object | Close_object | Open_array | Close_array | List_delim |
Assign_delim | Quote | String_literal String deriving (Show, Eq, Read)
data JsonElement = FullJsonArray [JsonElement] | StringValue String deriving (Show, Eq, Read)
tokens :: [(Char, Token)]
tokens = [
('{', Open_object),
@ahjones
ahjones / latin.clj
Created October 29, 2011 16:04
Latin square
(ns latin.core
(:use [clojure.contrib.seq-utils :only [positions]]))
(def sqrt (memoize (fn [x] (Math/sqrt x))))
(def alphabet (memoize (fn [sq] (range 1 (sqrt (inc (count sq)))))))
(defn rows
"A sequence of the rows of the square"
[sq]