Map Coloring

In geometry, there’s a theorem that no more than four colors are required to fill in regions on a map so that all connected regions have different colors. Let’s build a Prolog program to pick colors for countries in a map. Let’s think about how to represent the problem.

My first inclination for solving such problems was to think about building an algorithm to get to a solution. That’s rarely the best way to think about a Prolog problem. Instead, it’s best to think about building rules and facts that describe the problem domain.

As a developer who is used to thinking in terms of types, my next inclination is to assign atoms to each dimension. Our problem domain has two types of entities, countries and colors. You might be tempted ...

Get Programmer Passport: Prolog now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.