---
title: "地图着色——core.logic求解"
author: "Aaron5"
date: "2015-06-16T13:24:11Z"
tags: []
categories: ["编程语言"]
slug: "core-logic"
draft: false
lastmod: "2015-06-23T10:52:50Z"
id: 2219988
url: "https://clojure.iteye.com/blog/2219988"
---

记得很久很久之前写过一篇[《七周七语言——地图着色》](http://clojure.iteye.com/blog/1727541)。用core.logic求解下。
![](http://dl.iteye.com/upload/attachment/0076/6860/361e23b1-b393-3719-b177-c0af8dace490.png)

依赖包：

```leiningen

[org.clojure/core.logic "0.8.10"]

```



```clojure

(use 'clojure.core.logic)

(nth (run 1 [q]
     (fresh [tn ms al ga fl]
            (everyg #(membero % [:red :blue :green]) [tn ms al ga fl])
            (!= ms tn) (!= ms al) (!= al tn)
            (!= al ga) (!= al fl) (!= ga fl) (!= ga tn)
            (== q {:tennessee tn
                   :mississippi ms
                   :alabama al
                   :georgia ga
                   :florida fl})
            )) 0)

```


输出结果：{:tennessee :blue, :mississippi :red, :alabama :green, :georgia :red, :florida :blue}