cryptarithmetic-puzzle

Some implicit constraint

喜欢而已 提交于 2019-12-24 07:58:38
问题 When i execute this code(shown below) , it always sets implicit kind of constraint. As you can see below , it always says that D1 = D2 but there is no such explicit constraints nor any pattern matching which forces this. Or in otherwords there is some reference between D1 and D2 such that whenever D1 gets initialized, D2 gets automatically initialized. I can't see how this is happening. Can someone explain me, i tried ot figure it out with debugger but it did not help. It's a puzzle "GERALD +

Efficient way of Solving Cryptarithms

北城余情 提交于 2019-12-21 17:00:44
问题 Hi i came across this puzzle which is a subset of famous kind of word and numbers based puzzles called Cryptarithms. Say you have an expression as S E N D + M O R E = M O N E Y Now the interesting part there is that, each alphabet is representing a unique digit from 0-9. I wanted to write a generalized solver, but i ended up writing a brute forced solution for it. Any takers as how can i solve it? I think it can be solved using predicate logic or set theory. And i'm particularly interested in

How to Solve Cryptarithmetic Puzzle in Prolog

不羁的心 提交于 2019-12-12 10:56:48
问题 I have to write a Prolog program for solving a cryptarithmetic puzzle. I need to write a function solve([A, M, P, D, Y]) which assigns the variables [A, M, P, D, Y] to values from 0 to 9 so that it satisfies the equation AM+PM=DAY. Each variable is assigned to a different value, and A, P, and D cannot be equal to 0. I started writing this function, but ran into problems running my program. I set the restrictions of A, P, and D not being zero. As I was going through the algorithm, I realized

cryptarithmetic prolog test fails recursion idea

末鹿安然 提交于 2019-12-11 08:46:22
问题 I need to test this code for crypt arithmetic for two + two = four but it is giving me false which is wrong. I need to know why is this happening. It works for donald+robert= gerald or it+is=me. I got the idea of how recursion works but since i cannot debug it I have no idea what is wrong. sum(N1,N2,N) :- sum1(N1,N2,N,0,0,[0,1,2,3,4,5,6,7,8,9], _). sum1([], [], [], C,C,D,D). sum1([D1|N1], [D2|N2], [D|N], CR, C, Digs1, Digs) :- sum1(N1,N2,N, CR, CLN, Digs1, Digs2), digsum(D1,D2, CLN, D, C,

Prolog “singleton variable” warning

狂风中的少年 提交于 2019-12-01 05:18:15
问题 I'm new to Prolog and royally confused! I keep getting a "singleton variable for [WMAPDY]" warning. I read somewhere that sometimes that warning is useless. I also read that the program will not compile all the clauses because of the warning? The program I'm trying to do is a crypt-arithmetic puzzle that is supposed to "solve" AM+PM=DAY. If anyone could help with this error and also wether the singleton variable warning is always important I'd greatly appreciate it!! Scott solve([A,M,P,D,Y]):

Faster implementation of verbal arithmetic in Prolog

≡放荡痞女 提交于 2019-11-26 07:49:05
问题 I already made a working generalized verbal arithmetic solver in Prolog but it\'s too slow. It takes 8 minutes just to run the simple expression S E N D + M O R E = M O N E Y. Can someone help me to make it run faster? /* verbalArithmetic(List,Word1,Word2,Word3) where List is the list of all possible letters in the words. The SEND+MORE = MONEY expression would then be represented as verbalArithmetic([S,E,N,D,M,O,R,Y],[S,E,N,D],[M,O,R,E],[M,O,N,E,Y]). */ validDigit(X) :- member(X,[0,1,2,3,4,5