removing the largest item from the list
From: Yupar Nyo (yupar_nyo_at_bigpond.com)
Date: 03/13/04
- Next message: Martin Sondergaard: "Re: removing the largest item from the list"
- Previous message: Jurgen Van Gael: "Prolog & Incompleteness"
- Next in thread: Martin Sondergaard: "Re: removing the largest item from the list"
- Reply: Martin Sondergaard: "Re: removing the largest item from the list"
- Reply: seguso: "Re: removing the largest item from the list"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 13 Mar 2004 14:30:34 GMT
Hi,
I am new to prolog and struggling with lists now. What is the best way to
remove the largest number from the list? (remove the one at the front most
only if it occurs more than once in the list). I know how to find the
largest item from the list but do not know how to remove it. How to write
"helper" predicates?
E.g., remove_largest([1,3,5,9,7,4,5],X)? %largest item is 9
X=[1,3,5,7,4,5]
:remove_largest([1,9,5,9,7,4,5],X)? %largest item is 9 in position 2
X=[1,5,9,7,4,5] % note that the second occurence of the largest number
remains.
Thanks.
Kind Regards,
Yupar
- Next message: Martin Sondergaard: "Re: removing the largest item from the list"
- Previous message: Jurgen Van Gael: "Prolog & Incompleteness"
- Next in thread: Martin Sondergaard: "Re: removing the largest item from the list"
- Reply: Martin Sondergaard: "Re: removing the largest item from the list"
- Reply: seguso: "Re: removing the largest item from the list"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|