INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

program now working correclty

program now working correclty

(OP)
hi i have to write a program which solves problem
B+G=D
B+C=A
C+E+G=F
if D<A then C=2 and if D>=A then E=2
each letter equals different number from 0 to 9 and have to find solution with lowest max(max is highest number in current solution)
i wrote program but some parts seem to not be used and cant figure out why

CODE -->

domains
Intlist = Integer*


predicates
nondeterm rozwiazanie
nondeterm sprawdz(Intlist)
nondeterm wariacja(Integer,Intlist,Intlist)
nondeterm usun(Integer,Intlist,Intlist)
nondeterm max(Integer,Intlist,Intlist)
nondeterm przy(Intlist)
nondeterm writte
database - mydb
max2(Integer)
max3(Integer)
rozw(Symbol,Integer)
goal
rozwiazanie.
clauses
rozwiazanie:-
wariacja(10,[0,1,2,3,4,5,6,7,8,9],[A,B,C,D,F,E,G]),
sprawdz([A,B,C,D,F,E,G]),
 write("E= ",E," A= ",A," B= ",B," C= ",C," D= ",D," F= ",F," G= ",G),nl,%if needed writes every solution
 max(0,[A,B,C,D,E,F,G],[A,B,C,D,E,F,G]),nl,fail.
rozwiazanie:-writte.
 

sprawdz([A,B,C,D,F,E,G]):-D>=A,B+G=D,B+C=A,C+E+G=F,E=2;
D<A,B+G=D,B+C=A,C+E+G=F,C=2.

wariacja(3,_,[]):-!. 
wariacja(N,L,[H|T]):-		usun(H,L,LW),		NN=N-1,			wariacja(NN,LW,T).

usun(E,[E|T],T). 
usun(E,[H|T1],[H|T2]):-		usun(E,T1,T2).


max(T,[],[A,B,C,D,E,F,G]):-T=7,    %<-part 1 starts here
max3(X),write("x=  ",X),nl,
max2(Y),X<Y,
asserta(max2(X),mydb),       
przy([A,B,C,D,E,F,G]),write("pra"),nl,
asserta(max3(0),mydb), 
!.                                   %<-part 1 ends here

max(T,[GG|TT],RR):-                 $part2 starts here
max3(X),T>1,TTT=T+1,
GG>X,
asserta(max3(GG),mydb),write("aktualne max =",GG),nl,
max(TTT,TT,RR).                                            %<ends here

max(T,[GG|TT],RR):-       % part 3 starts here
T=0,TTT=T+1,
GG>T,
asserta(max3(GG),mydb),write("t=",T,"   max=",GG),nl,
max(TTT,TT,RR).   $part 3 ends here

przy([A,B,C,D,E,F,G]):- 
asserta(rozw("A",A),mydb),write("przyp A"),nl,
asserta(rozw("B",B),mydb),
asserta(rozw("C",C),mydb),
asserta(rozw("D",D),mydb),
asserta(rozw("E",E),mydb),
asserta(rozw("F",F),mydb),
asserta(rozw("G",G),mydb).


writte:- %write solution on screen using facts made by program
rozw("A",A),
rozw("B",B),
rozw("C",C),
rozw("D",D),
rozw("E",E),
rozw("F",F),
rozw("G",G),
max3(T),
write("best solution a=",A," b=",B," c=",C," d=",D," e=",E," f=",F," g=",G,"  max =",T).

max2(100).
max3(1).
rozw("A",1).
rozw("B",1).
rozw("C",1).
rozw("D",1).
rozw("E",1).
rozw("F",1).
rozw("G",1). 
main problem is with parts 1-3 (think rest of program is fine) i trying things and think part 3 is working but if i use "write" i can see part 1 and 2 is not even executed

hope someone can help

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close