地图着色——core.logic求解
程序员文章站
2022-07-14 14:44:30
...
记得很久很久之前写过一篇[url=http://clojure.iteye.com/blog/1727541]《七周七语言——地图着色》[/url]。用core.logic求解下。
[img]http://dl.iteye.com/upload/attachment/0076/6860/361e23b1-b393-3719-b177-c0af8dace490.png[/img]
依赖包:
输出结果:{:tennessee :blue, :mississippi :red, :alabama :green, :georgia :red, :florida :blue}
[img]http://dl.iteye.com/upload/attachment/0076/6860/361e23b1-b393-3719-b177-c0af8dace490.png[/img]
依赖包:
[org.clojure/core.logic "0.8.10"]
(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}