地图着色,要求相邻的州之间不能同色。有red,green,blue可用。
prolog解决代码:
different(red, green). different(red, blue). different(green, red). different(green, blue). different(blue, red). different(blue, green). coloring(Alabama, Mississippi, Georgia, Tennessee, Florida) :- different(Mississippi, Tennessee), different(Mississippi, Alabama), different(Alabama, Tennessee), different(Alabama, Mississippi), different(Alabama, Georgia), different(Alabama, Florida), different(Georgia, Florida), different(Georgia, Tennessee).
这个逻辑小孩子都可以理解。某些时候,你要问你自己。。。。。。(书中看到这句话,小流了一些汗,突然明白一点:一门编程语言可怕的不是语法,可怕的是一门编程语言会限制你的思维方式)