Skip to content

Instantly share code, notes, and snippets.

@ahoy-jon
Created January 23, 2014 00:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahoy-jon/5189e9384e1a8197f6a2 to your computer and use it in GitHub Desktop.
Save ahoy-jon/5189e9384e1a8197f6a2 to your computer and use it in GitHub Desktop.
Solution for https://github.com/jeanlaurent/secretSanta in core.logic
(ns cdl.santa
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
;; https://github.com/jeanlaurent/secretSanta
(def data
(partition 2 '[Walter White
Skyler White
Gustavo Fring
Saul Goodman
Jesse Pinkman
Henry Schrader
Marie Schrader]))
(defne oreo
"MMmmm COOOKIES" ;; I don't know how to name that one
[x y z]
([a a a])
([a b a] (!= a b))
([b a a] (!= a b)))
(defne zipo
"zipped = (map (partial vector) xl yl)"
[xl yl zipped]
([xs ys ()] (oreo xs ys ()))
([[x . xs] [y . ys] [z . zs]]
(== z [x y])
(zipo xs ys zs)))
(defne ruleo [z]
([()])
([[[[_ x] [_ y]] . as]] ; extract names of the first pair
(!= x y)
(ruleo as)))
(run 10 [couple]
(fresh [result]
(zipo data result couple)
(permuteo data result)
(ruleo couple)))
@ahoy-jon
Copy link
Author

In fact, oreo is a materialized version of membero, so it's not really useful :

(defne zipo
  "zipped = (map (partial vector) xl yl)"
  [xl yl zipped]
  ([xs ys ()] (membero () [xs ys]))
  ([[x . xs] [y . ys] [z . zs]]
     (== z [x y])
     (zipo xs ys zs)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment