Skip to content

Instantly share code, notes, and snippets.

@nathanic
Created January 15, 2016 18:50
Show Gist options
  • Save nathanic/71fb4610ced6ebe1b41e to your computer and use it in GitHub Desktop.
Save nathanic/71fb4610ced6ebe1b41e to your computer and use it in GitHub Desktop.
(ns lazybot.plugins.logicplayground
(:refer-clojure :exclude [==])
(:use clojure.core.logic)
(:require clojure.core.logic.fd :as fd)
)
(comment
(run* [q]
(fresh [a b c d e f g h i j k l m n o p]
; every hex is either a empty (0) or filled (1)
(everyg #(fd/in % (fd/domain 0 1)) [a b c d e f g h i j k l m n o p])
(fd/eq
(= (+ a b c) 1)
(= (+ d e f g) 2)
(= (+ h i) 1)
(= (+ j k l m) 2)
(= (+ n o p) 1)
(= (+ a d) 1)
(= (+ b e h j) 2)
(= (+ m p) 1)
(= (+ g i l o) 2)
(= (+ j n) 1)
(= (+ d h k o) 1)
(= (+ c g) 1)
(= (+ b f i m) 1)
(= (+ a d e h j k n) 4)
(= (+ a b c d e f g h i j k l m n o p) 7)
; added equation from uncovering e
(= (+ h i j k l) 2)
)
(== q [a b c d e f g h i j k l m n o p])))
; initial run produced 2 results:
;=> ([1 0 0 0 1 0 1 0 1 1 1 0 0 0 0 1]
; [1 0 0 0 1 0 1 1 0 0 0 1 1 1 0 0])
; both are possible. makes sense, we had 16 variables and 15 equations.
; but it turns out we get another equation when we uncover e
; in the end we got [1 0 0 0 1 0 1 1 0 0 0 1 1 1 0 0], which was right
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment