I have been asked to solve a Cryptarithmetic Puzzle using prolog:

```
GIVE
* ME
------
MONEY
```

The above is the puzzle, I cannot figure out where is the problem, the result always returns false. Plus I am not allowed to use any library in SWI-Prolog.

```
solve( Z ) :- assign( Z, [0,1,2,3,4,5,6,7,8,9] ), check( Z ).
find( VAL, G, I, V, E ) :- VAL is G * 1000 + I * 100 + V * 10 + E.
find2( VALR, M, E ) :- VALR is M * 10 + E.
find3( VALA, M, O, N, E, Y ) :- VALA is M * 10000 + O * 1000 + N * 100 + E * 10 + Y.
check( Z ) :-
G #>= 1, M #>= 1,
find( VAL, G, I, V, E ), find2( VALR, M, E ), find3( VALA, M, O, N, E, Y ), VAL * VALR =:= VALA .
assign( Z, L ) :- permute( L, Z ).
/* permute is similar to all_difference in swi-prolog */
addany(X,K,[X|K]).
addany(X,[F|K],[F|L1]) :- addany(X,K,L1).
permute([],[]).
permute([X|K],P) :- permute(K, L1), addany(X, L1, P).
===============================================================
to solve, we execute solve([G,I,V,E,M,O,N,Y]).
```

## comments: