A problem??
From: desert_bise (shazadi.gul_at_gmail.com)
Date: 03/05/05
- Previous message: Brian Hulley: "Re: swi prolog and odbc connectivity"
- Next in thread: Bart Demoen: "Re: A problem??"
- Reply: Bart Demoen: "Re: A problem??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 4 Mar 2005 23:25:10 -0800
HI All, i am new to prolog and have tried to solve the problem using
my own code.the prooblem has a list as follows:-
['first','second','third','first','second']
I use the following code to get the number of each elements in the
list and display them
get_items([], Length, ElemList).
get_items(List, Length, ElemList):-
length(List, Length),
last(List, Elem),
delete(List, Elem, List1),
length(List1, Length1),
N is Length - Length1,
item_to_remove(N,Elem,ElemList,ElemList1),
write(Elem), tab(2), write(N), tab(2),
get_items(List1, Length1, ElemList1).
item_to_remove(N,Elem,ElemList,ElemList1):-
N > 1,
append(ElemList,Elem,ElemList1);
ElemList1 = ElemList.
I run as this code to try and get a seperate list of items that occur
in the list more than once.
second 2 first 2 third 1
Length = 5
ElemList = []
It correctly displays the number of times an item appears in the list
but the list of items appearing more than once is empty? I dont know
why?.
- Previous message: Brian Hulley: "Re: swi prolog and odbc connectivity"
- Next in thread: Bart Demoen: "Re: A problem??"
- Reply: Bart Demoen: "Re: A problem??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|