-1

Having a bit of trouble doing research and trying to solve this problem in PROLOG. I have to implement a cryptarithmetic-puzzle solver able to solve any possible cryptarithmetic-puzzle. I'll explain in a bit more detail below.

Given as input a list which has a variable number of elements (at least 3), for example [send, more, money] which will be the equivalent of SEND+MORE=MONEY, implement a program that outputs appropriate messages. If there is a solution to the input the program will output a list of digits assigned to each character or the expression where each character is replaced with its' assigned digit.

I appreciate all answers, though I would appreciate a complete answer more. From my past experiences I have learned I understand things better if I see a full solution to something, so that I can follow it line by line and see what makes the solution tick.

  • No, unfortunately that doesn't really answer my question, and I believe structures like "a simple search would immediately[...]" are considered unfriendly as seen here: https://stackoverflow.com/conduct#unfriendly-language I appreciate your input, but unfortunately that doesn't really help. I have seen the question, but I couldn't find the answer there regarding my question. Hope that clarifies. – Hachiko1337 Apr 06 '20 at 10:15
  • 1
    @Hachiko1337 Okay, in this case it is best to open a new question where you post actual code so as to start the discussion. Also try to post code to demonstrate the problem. Ideally use the testing framework described here: [plunit](https://www.swi-prolog.org/pldoc/doc_for?object=section(%27packages/plunit.html%27)). It takes a bit to get started but once you do, it's worth it. [Programmers Love Writing Tests](http://members.pingnet.ch/gamma/junit.htm) (that one's for Java though). – David Tonhofer Apr 06 '20 at 14:45
  • [here](https://stackoverflow.com/a/11011680/849891) is a simple answer in the linked entry marked as duplicate (there are more advanced other answers there as well) which directly answers this question AFAICT, with a working runnable code. if you have trouble amending that code to your specific needs, don't hesitate to post new question with the specifics. – Will Ness Apr 08 '20 at 17:07

1 Answers1

1

This is a great classic.

Check out the solution based on CLP(FD) library(clpfd): CLP(FD): Constraint Logic Programming over Finite Domains

or the classic code on (randomly selected) this page, which also contains the CLP(FD) example, but using the ECLiPSe solver.

David Tonhofer
  • 12,954
  • 4
  • 44
  • 46