removing the largest item from the list

From: Yupar Nyo (yupar_nyo_at_bigpond.com)
Date: 03/13/04


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



Relevant Pages

  • Simple q: setting the value of one field based on a form selection
    ... Newbie to VBA who is struggling along, but I've run into a minor (but ... I have a form that lists a number of columns from a table. ... One of the columns is uses a lookup function. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Beware Getting Reported
    ... For you guys struggling with full ignore lists, ... would perma /ignore folks for fun banter in general chat anyway. ... on the same server. ...
    (alt.games.warcraft)
  • Re: Assignment for Perl Class- hurting my brain
    ... are you struggling with this part? ... This "slurps the entire file into the array. ... true and thus probably an infinite loop. ... rest, use parens around your lists, so you can see they are lists: ...
    (perl.beginners)
  • Stuck for a Solution
    ... I have two sets of data that I am struggling to combine withiout having to do ... both lists, some only in one list and not the other. ... to combine the two sections of data into one list, eliminate the duplicate ...
    (microsoft.public.excel.misc)
  • Formatting tags on numbered lists
    ... Mac OS X 10.5 (Leopard) ... I am struggling with automatically numbered lists. ... My document has a numbered list in sections alternating with blocks of un-numbered text. ...
    (microsoft.public.mac.office.word)