[Solved] Prolog Define Predicates [closed]


Try this one 🙂 The main idea is to accumulate number of hours in the predicate min by subtracting 60 from total time and when the total time is lower than 60 we can unify counted hours from accumulator with H variable and rest of time with M variable.

minutes(X,H,M):-                     %main predicate
    min(X,0,H,M).

min(X,H,ResultH,ResultM):-           %ending condition of recursion
    X<60,
    ResultH is H,                    %unification with counted hours
    ResultM is X.

min(X,H,ResultM,ResultH):-           %recursive predicate
    X >= 60,
    X2 is X-60, H2 is H+1,           %subtracting from total time
    min(X2,H2,ResultM,ResultH).

2

solved Prolog Define Predicates [closed]