Re: Help I'm stuck!

From: reader (no-spam_at_sonic.net)
Date: 08/12/04

  • Next message: reader: "Re: How to return clause in findall/3"
    Date: Thu, 12 Aug 2004 19:37:51 GMT
    
    

    rhapsody wrote:

    > Help I'm stuck, can anybody tell me how to retrieve sc() with the maximum
    > score? I couldn't figure it out, just started learning and too used to
    > procedural programming concept. Below are the codes I'm stuck in... using
    > Visual Prolog 5.2
    >
    > Database
    > sc(symbol Sid,symbol Cid, integer ExamScore).
    >
    > Clauses
    > sc("S1","C1",55).
    > sc("S1","C2",60).
    > sc("S1","C3",70).
    > sc("S2","C1",100).
    > sc("S2","C2",80).
    > sc("S3","C1",40).
    > sc("S3","C2",30).
    >
    > Predicates
    > elem_max(integer,integer,integer)
    > nondeterm high()
    > Clauses
    > high():-
    > sc(S,C,Score),
    > write("S: ", S, " C: ", C, " Score: ",Score),
    > nl,
    > fail.
    >
    > elem_max(E1,E2,E1):- E1 >= E2, !.
    > elem_max(_,E2,E2).
    >
    > Goal
    > high().
    >

    /*
        You have declared your data to be a database, so just
    use retract to find the maximum score:
    */

    Predicates
             find_max(integer,integer).

    Clauses

        find_max(In,Out) :-
           retract(sc(_,_,ExamScore)),
           !,
           elem_max(In,ExamScore,Next),
           find_max(Next,Out).
        find_max(In,In).

    GOAL find_max(0,Max).

    --
    sequitur AT sonic DOT net
    

  • Next message: reader: "Re: How to return clause in findall/3"

    Relevant Pages