fork download
  1. % 色の定義
  2. color(red).
  3. color(green).
  4. color(blue).
  5. color(yellow).
  6.  
  7. % 隣接関係
  8. adjacent(鶴見, 神奈川).
  9. adjacent(神奈川, 西).
  10. adjacent(西,).
  11. adjacent(,).
  12. adjacent(, 港南).
  13. adjacent(港南, 磯子).
  14. adjacent(磯子, 金沢).
  15. adjacent(金沢,).
  16. adjacent(, 港南).
  17. adjacent(, 保土ケ谷).
  18. adjacent(保土ケ谷, 西).
  19. adjacent(保土ケ谷,).
  20. adjacent(, 瀬谷).
  21. adjacent(瀬谷,).
  22. adjacent(, 戸塚).
  23. adjacent(戸塚,).
  24. adjacent(都筑, 港北).
  25. adjacent(都筑, 青葉).
  26. adjacent(都筑,).
  27. adjacent(港北, 神奈川).
  28. adjacent(, 青葉).
  29. adjacent(港北, 鶴見).
  30. adjacent(保土ケ谷,).
  31.  
  32. % 色付け:すべての区に色を割り当てる
  33. coloring([]).
  34. coloring([-| T]) :-
  35. color(),
  36. forall(member(隣接区-隣接色, T),
  37. ((adjacent(, 隣接区); adjacent(隣接区,)) -> 色 \= 隣接色 ; true)),
  38. coloring(T).
  39.  
  40. % 実行述語
  41. run :-
  42. coloring([
  43. 鶴見-_, 神奈川-_, 西-_,-_,-_, 港南-_,
  44. 磯子-_, 金沢-_,-_, 保土ケ谷-_,-_, 瀬谷-_,
  45. -_, 戸塚-_, 都筑-_, 港北-_,-_, 青葉-_
  46. ]),
  47. write('4色で塗り分け可能'), nl.
  48.  
  49. % 実行
  50. :- run.
  51.  
Success #stdin #stdout #stderr 0.02s 6912KB
stdin
run
stdout
Standard output is empty
stderr
Warning: /home/tBpBxE/prog:50:
	Goal (directive) failed: user:run
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit