I'm trying to write a program to solve general cryptarithmetic puzzles such as AM+PM=DAY, SEND+MORE=MONEY..
The program I've written is:
gsolve([H1,T1],[H2|T2],[H3|T3]):-
gsolvehelper([H1,T1],[H2|T2],[H3|T3],[0,1,2,3,4,5,6,7,8,9],0).
gsolvehelper([H1,T1],[H2|T2],[H3|T3],D,C):-
( var(H1)->select(H1,D,D1);D1=D),
( var(H2)->select(H2,D1,D2);D2=D1),
( X1 is H1+H2+C),
( H3 is mod(X1,10)),
( C1 is X1//10),
gsolvehelper(T1,T2,T3,D2,C1).
The input is of the form:
gsolve([A,M],[P,M],[D,A,Y]).
The head of the first two lists is added to the carry to find the head of the third list and the new carry and so on.
The error I get is:
ERROR: is/2: Type error: `[]' expected, found `[2,_G3922]' ("x" must hold one character)
I cannot figure out what this error is. Can someone please help me with this?
'.'/2: ... [_Gxxxx]
, notis/2: ...[2,_Gxxxx]
, which probably means you have a malformed list construct occurring (the actual list predicate is'.'
, so[H|T]
is really'.'(H,T)
in Prolog). – lurker