Skip to content

Instantly share code, notes, and snippets.

@pbostrom
pbostrom / gist:5342129
Last active December 15, 2015 23:39 — forked from swannodette/gist:3217582
Sudoku solver via https://gist.github.com/swannodette/3217582, modified for Twitter REPL
;; works with core.logic 0.8.4
(require '[clojure.core.logic :refer :all])
(require '[clojure.core.logic.fd :as fd])
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
(defn init [vars hints]
@pbostrom
pbostrom / sum-list.clj
Last active December 13, 2015 21:58 — forked from swannodette/notes.clj
Generates lists of size M containing natural numbers which add up to N (forked from David Nolen with some tweaks to run on cwo.io)
(require '[clojure.core.logic :refer :all])
(require '[clojure.core.logic.fd :as fd])
(defn sumo
([l n] (sumo l 0 n))
([l acc n]
(matche [l]
([[]] (fd/== acc n))
([[x . r]]
(fresh [nacc]
@pbostrom
pbostrom / gist:3251454
Created August 3, 2012 20:56 — forked from llasram/gist:3251293
Transaction side effects
(let [q (ref []), x (ref 0)]
(defn run-side-effects [_]
(let [fs (dosync
(let [q' @q]
(ref-set q [])
q'))]
(doseq [f fs] (f))))
(defn alter-and-order-side-effects []
(dosync