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 sudoku | |
(:refer-clojure :exclude [==]) | |
(:use clojure.core.logic)) | |
(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] |
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 evil-norvig | |
[[0 0 0 0 0 6 0 0 0] | |
[0 5 9 0 0 0 0 0 8] | |
[2 0 0 0 0 8 0 0 0] | |
[0 4 5 0 0 0 0 0 0] | |
[0 0 3 0 0 0 0 0 0] | |
[0 0 6 0 0 3 0 5 4] | |
[0 0 0 3 2 5 0 0 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
(defn distincto [s] | |
(if (seq s) | |
(all | |
(distinctfd (first s)) | |
(distincto (next s))) | |
s#)) | |
(defn all-infd [xs d] | |
(if (seq xs) | |
(all |
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
(defne all-distinctfd [l] | |
([()]) | |
([[h . t]] | |
(distinctfd h) | |
(all-distinctfd t))) | |
(run 1 [q] | |
(fresh [a1 a2 a3 a4 | |
b1 b2 b3 b4 | |
c1 c2 c3 c4 |
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 sud | |
(:require [clojure.set :as s] | |
[clojure.pprint :as pp])) | |
(defn possible | |
"Possible values for a given position" | |
[[x y] board] | |
(let [horizontal (set (board x)) | |
vertical (reduce (fn [a c] (conj a (c y))) #{} board) | |
x' (* (quot x 3) 3) |
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 fact' [fact n] | |
(if (= n 0) 1 | |
(* n (fact (dec n))))) |
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 clog | |
(:refer-clojure :exclude [==]) | |
(:use clojure.core.logic)) | |
;; ------------------ | |
(def db | |
#{ | |
[#uuid "9d6280a3-7043-4e7e-9187-ad800743406a" :last-name "Downey"] | |
[#uuid "9d6280a3-7043-4e7e-9187-ad800743406a" :street "Hanam"] |
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
(do | |
(defrel id-first p1 p2) | |
(defrel id-email p1 p2) | |
(defrel id2-email p1 p2) | |
(defrel id2-height p1 p2) | |
(fact id-first 1 "John") | |
(fact id-email 1 "[email protected]") | |
(fact id-first 2 "Jane") | |
(fact id-email 2 "[email protected]") | |
(fact id2-email 100 "[email protected]") |
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 queries | |
(:refer-clojure :exclude [==]) | |
(:use [clojure.core.logic]) | |
(:use [datomic.api :only [q]])) | |
(defn query [rule xs] | |
(let [prule (prep rule)] | |
(map #(binding-map* prule (prep %)) xs))) | |
;; --- |
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 bench [n f] | |
(let [rand-str #(str (java.util.UUID/randomUUID)) | |
emails (repeatedly n rand-str) | |
name-email (reduce (fn [res em] | |
(conj res (vector (rand-str) (rand-str) em))) | |
[] emails) | |
email-height (reduce (fn [res em] | |
(conj res (vector em (rand-int 100)))) | |
[] emails)] | |
(time (count (f name-email email-height))))) |