Re: Riddle Solver send+more=money
- From: Djamé <djame@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 25 Apr 2005 12:18:57 +0200
Torkel Franzen a écrit :
Andreas Kochenburger <akk@xxxxxxxxxx> writes:
I fumbled and fumbled... all I get is error messages. I am looking for an elegant solution, not a brute force looping, that would be faster in C.
What's wrong with brute force? A second here or there is of no
consequence.
A Google search for send more money prolog yields many solutions.
Here is one, from
http://clip.dia.fi.upm.es/~vocal/public_info/seminar_notes/node13.html.
smm :-
X = [S,E,N,D,M,O,R,Y],
Digits = [0,1,2,3,4,5,6,7,8,9],
assign_digits(X, Digits),
M > 0, S > 0,
1000*S + 100*E + 10*N + D +
1000*M + 100*O + 10*R + E =:=
10000*M + 1000*O + 100*N + 10*E + Y,
write(X).
select(X, [X|R], R). select(X, [Y|Xs], [Y|Ys]):- select(X, Xs, Ys).
assign_digits([], _List). assign_digits([D|Ds], List):- select(D, List, NewList), assign_digits(Ds, NewList).
Some times ago, I've found a very interesting page (I archived it obecause I'm fed up to loose all the cool pages every year) about the magic of DCG, you'll find some cool way to solve the SEND money problem..
http://djame.seddah.free.fr/papiers/DCG_magic.html
have fun.....
Djamé
.
- Follow-Ups:
- Re: Riddle Solver send+more=money
- From: Torkel Franzen
- Re: Riddle Solver send+more=money
- References:
- Riddle Solver send+more=money
- From: Andreas Kochenburger
- Re: Riddle Solver send+more=money
- From: Torkel Franzen
- Riddle Solver send+more=money
- Prev by Date: Re: Riddle Solver send+more=money
- Next by Date: Re: Riddle Solver send+more=money
- Previous by thread: Re: Riddle Solver send+more=money
- Next by thread: Re: Riddle Solver send+more=money
- Index(es):
Relevant Pages
|
|