Thank kahleen very much. You did a great job. I am in a big respect of you. I wrote the third rule, it was very easy after your help. The program solves the problem correctly ;)
Thank you very much. I have done insert with "-" sign, but have some problems with 'value' predicate.
I wrote:
value(L, X) :-
((member('+', L)) -> append(L1, ['+' | L2], L), decimal(L1, 0, A), value(L2,B), X is A + B);
((member('-', L)) -> append(L1, ['-' | L2], L), decimal(L1, 0, A)...
Thank you.
% insert(L, R) - inserts any number of plus signs between
% elements in L, resulting R
insert([], []).
insert([H | T], [H, '+' | T1]) :-
T \= [],
insert(T, T1).
insert([H | T], [H | T1]) :-
insert(T, T1).
% decimal(L, X, N) - if L contains no '+' signs, computes
% in N...
I have looked all the threads in this forum but found nothing what would help me. If I missed one maybe could you give me a link? I still have no ideas.. :( Very grateful for any help.
Hello,
I am quite new to prolog and need to write this program, but have no ideas. I would be very grateful for any help.
"Add signs"
The list of the digits (1-9) is given. You need to add operation signs (+, -), that expression of the arithmetic would be the given number (digits in a row...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.