Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write Prolog rules as described in the questions below. You may use any Prolog b

ID: 3899279 • Letter: W

Question

Write Prolog rules as described in the questions below. You may use any Prolog builtin predicates.

A time, in hours and minutes, is described by the time structure. For example,
9 hours and 33 minutes would be encoded as time(9,33).
Write the rule tdelta that computes the difference between two times, reported in hours
and minutes. The absolute value of the time difference is computed (that is, time differences
calculated are always positive values).
tdelta(T1,T2,T3) if time T3 is equal to the absolute value of the difference between time
T1 and time T2. For example:
?- tdelta(time(10,10),time(12,20),D).
D = time(2, 10).
?- tdelta(time(10,30),time(12,20),D).
D = time(1, 50).
?- tdelta(time(14,30),time(12,20),D).
D = time(2, 10).

Explanation / Answer

tdelta(time(H1,M1), time(H2,M2),
[hours(H), mins(M)] ) :-
H3 is H1 - H2,
M3 is M1 - M2
(M3 < 0 ->
M is M3 + 60,
H is H3 - 1
;
H = H3,
M = M3).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote