2

I'm using Sicstus Prolog, and I'm trying to solve the Domino Puzzle.

I have a list with triplets, which I need to set the domain of. I know how to set the domain of a single variable, or a list of single variables, but how can I do it if my list has triplets, and each of the elements of the triples has a different domain?

DV = [R1-C1-D1, R2-C2-D2, ... , R15-C15-D15]

What I want to do is this:

domain(R1, 1, 4)
domain(C1, 1, 4)
domain(D1, 0, 1)
domain(R2, 1, 4)
domain(C2, 1, 4)
domain(D2, 0, 1)
....
domain(R15, 1, 4)
domain(C15, 1, 4)
domain(D15, 0, 1)

How can I do this without having to explicitly state each of the variables?

mat
  • 40,498
  • 3
  • 51
  • 78
Tirafesi
  • 1,297
  • 2
  • 18
  • 36

1 Answers1

3

Describe the domains for one element:

eldoms(R-C-D) :-
   domain(R, 1, 4),
   domain(C, 1, 4),
   domain(D, 0, 1).

And:

..., maplist(eldoms, RCDs), ...

using library(maplist).

Alternatively, using library(lambda):

..., maplist(
        \ (R-C-D) ^ (  domain(R, 1, 4),
                       domain(C, 1, 4),
                       domain(D, 0, 1) ), RCDs), ...
false
  • 10,264
  • 13
  • 101
  • 209
  • Hey! I'm trying to implement The Domino Puzzle in (sicstus) prolog (using only constraint logic). I've found a pretty detailed guide explaining the logic, but I'm having trouble actually implementing it. I was wondering if you could help me out, please? – Tirafesi Dec 16 '16 at 14:53