地图着色——core.logic求解
程序员文章站
2022-05-21 09:23:13
...
记得很久很久之前写过一篇《七周七语言——地图着色》。用core.logic求解下。
依赖包:
输出结果:{:tennessee :blue, :mississippi :red, :alabama :green, :georgia :red, :florida :blue}
依赖包:
[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}