在序言中,我们可以获得 map 着色问题的解决方案,如下所示:
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).
?- coloring(Alabama, Mississippi, Georgia, Tennessee, Florida).
Alabama = blue
Florida = green
Georgia = red
Mississippi = red
Tennessee = green
是否可以计算可能的 map 着色总数?
最佳答案
对于Anders解决方案,请注意,“coloring”一词应小写,这将给出正确的答案-6个解决方案。
aggregate_all(count, coloring(Alabama, Mississippi, Georgia, Tennessee, Florida), Count).
Count = 6.