Neuron 101

Solving by search / Constraint satisfaction

Türkçe

Plate21

Unit 2 · Topic 10 of 10

Constraint satisfaction

Medium, 8 min, 10 steps

WANTSAQNSWVTOrder1WA·2NSW·3NT·4Q·5SA·6V·7T·
Keyboard: left and right arrows change the step, space plays and pauses.

Step 1 of 10 Map

Seven regions

The seven regions of Australia are drawn as circles and neighbours are joined by lines. T is an island and has no neighbours. We have 3 colours.

Open in Colab
  1. RENKLER = ["kırmızı", "mavi",
  2. "sarı", "yeşil"][:3]
  3. def geri_izle(atama, sira):
  4. if len(atama) == len(sira):
  5. return atama
  6. b = sira[len(atama)]
  7. for r in RENKLER:
  8. if uyar(b, r, atama):
  9. atama[b] = r
  10. s = geri_izle(atama, sira)
  11. if s:
  12. return s
  13. del atama[b]
  14. return None
  15. def uyar(b, r, atama):
  16. return all(atama.get(k) != r
  17. for k in KOMSU[b])
atama
0
geri
0