For Programmers: Free Programming Magazines  


Home > Archive > Prolog > March 2005 > Newbie question about list









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Newbie question about list
Faraz Kunwar

2005-03-01, 3:58 am

hi

I have a list [a,b,a,c,a,c,b] I want to seperate the list to get
the resultas follows a=3, b=2, c=2, I thought about getting the total
length of the list then deleteing all occurances of a form list
subtracting the length1 from lentgh the new list would be [b,c,c,b]
then deleting b and getting length2 .....
but this takes foe ever and for large lists it would take too long
Is there a simpler method.
Bart Demoen

2005-03-01, 8:58 am

Faraz Kunwar wrote:
> hi
>
> I have a list [a,b,a,c,a,c,b] I want to seperate the list to get
> the resultas follows a=3, b=2, c=2, I thought about getting the total
> length of the list then deleteing all occurances of a form list
> subtracting the length1 from lentgh the new list would be [b,c,c,b]
> then deleting b and getting length2 .....
> but this takes foe ever and for large lists it would take too long
> Is there a simpler method.


There is a long thread in comp.lang.prolog named

Deleting elments of a list which are in it more than once

(the thread is still going, but is almost ending now I think)

Have a look there: it contains all you need to solve your problem
(and more :-)

Cheers

Bart Demoen
Pere Montolio

2005-03-01, 8:58 am

kfaraz@gmail.com (Faraz Kunwar) wrote in message news:<7949e3b6.0502281644.687405b8@posting.google.com>...
> hi
>
> I have a list [a,b,a,c,a,c,b] I want to seperate the list to get
> the resultas follows a=3, b=2, c=2, I thought about getting the total
> length of the list then deleteing all occurances of a form list
> subtracting the length1 from lentgh the new list would be [b,c,c,b]
> then deleting b and getting length2 .....
> but this takes foe ever and for large lists it would take too long
> Is there a simpler method.


In this group, thread "How to get the terms of a compund term
(predicate: simplfy)?", my post of 30/12/2004 shows an implementation
of an associative array.

If you adapt it a few, it solves the problem.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com