0

maplist/2我无法运行此代码,关于允许运行的列表我到底要说什么all_distinct/1

Solution = [A, B, C, D, E, F, G, H, I], 
Solution ins 1..9, 
maplist(all_distinct, Solution).

我明白了ERROR: Arguments are not sufficiently instantiated。我知道我对数字列表说得不够多,但我不知道我需要说什么。我想要一个 9 个不同数字 1 到 9 的列表。

这是我尝试执行时的跟踪:

   Call: (7) puzzle(_G548) ? creep
   Call: (8) _G548=[_G656, _G659, _G662, _G665, _G668, _G671, _G674, _G677|...] ? creep
   Exit: (8) [_G656, _G659, _G662, _G665, _G668, _G671, _G674, _G677|...]=[_G656, _G659, _G662, _G665, _G668, _G671, _G674, _G677|...] ? creep
   Call: (8) clpfd: ([_G656, _G659, _G662, _G665, _G668, _G671, _G674|...]ins 1..9) ? creep
   Call: (9) error:must_be(list, [_G656, _G659, _G662, _G665, _G668, _G671, _G674|...]) ? creep
   Exit: (9) error:must_be(list, [_G656, _G659, _G662, _G665, _G668, _G671, _G674|...]) ? creep
   Call: (9) clpfd:'__aux_maplist/2_fd_variable+0'([_G656, _G659, _G662, _G665, _G668, _G671, _G674|...]) ? creep
   Call: (10) clpfd:fd_variable(_G656) ? creep
   Call: (11) var(_G656) ? creep
   Exit: (11) var(_G656) ? creep
   Call: (11) true ? creep
   Exit: (11) true ? creep
   Exit: (10) clpfd:fd_variable(_G656) ? creep
   Call: (10) clpfd:'__aux_maplist/2_fd_variable+0'([_G659, _G662, _G665, _G668, _G671, _G674, _G677|...]) ? creep

看起来ins/2可能无法正常工作,然后仍然传递给maplist/2? 我不知道发生了什么。

4

1 回答 1

4

What you are doing is that you are making a list of variables, Solutions, and then Solutions ins 1..9 makes each variable an integer between 1 and 9.

all_distinct/1 expects a list, not an integer.

So, if you want a list of 9 distinct integers:

?- Solutions = [A,B,C,D,E,F,G,H,I],
   Solutions ins 1..9,
   all_distinct(Solutions).
L = [A, B, C, D, E, F, G, H, I],
A in 1..9,
all_distinct([A, B, C, D, E, F, G, H|...]),
B in 1..9,
C in 1..9,
D in 1..9,
E in 1..9,
F in 1..9,
G in 1..9,
H in 1..9,
I in 1..9.
于 2015-02-10T14:24:28.273 回答