Prolog language

profilevhramu223
Untitleddocument.pdf

Data.pl free(ann,slot(time(8,0,am),time(9,0,am))). free(ann,slot(time(10,0,am),time(11,0,am))). free(ann,slot(time(8,0,pm),time(9,0,pm))). free(bob,slot(time(7,0,am),time(8,30,am))). free(bob,slot(time(10,0,am),time(11,0,am))).

free(bob,slot(time(11,30,am),time(9,0,pm))). free(carla,slot(time(8,0,am),time(9,0,am))). free(carla,slot(time(10,0,am),time(10,15,am))). free(carla,slot(time(11,0,am),time(8,30,pm))). free(dave,slot(time(8,0,am),time(9,0,am))). free(dave,slot(time(10,0,am),time(11,0,am))). free(ed,slot(time(9,0,am),time(10,0,am))). Uniq.pl notin(_,​ ​[]). notin(V,​ ​[H|T])​ ​:-​ ​V​ ​\=​ ​H,​ ​notin(V,​ ​T). in(V,​ ​[H|_])​ ​:-​ ​V=H. in(V,​ ​[_|T])​ ​:-​ ​in(V,​ ​T). set([]). set([H|T])​ ​:-​ ​notin(H,​ ​T),​ ​set(T). has([],​ ​_). has([H|T],​ ​L)​ ​:-​ ​in(H,​ ​L),​ ​has(T,​ ​L). uniq(L,​ ​U)​ ​:-​ ​has(L,​ ​U),​ ​has(U,​ ​L),​ ​set(U). Meetone.pl #!/bin/gprolog​ ​--consult-file :-​ ​include('data.pl'). %​ ​Your​ ​code​ ​goes​ ​here. meetone(Person,​ ​slot(time(beginHour,​ ​beginMinute,​ ​beginPeriod),​ ​time(endHour,​ ​endMinute, endPeriod)))​ ​:-

free(Person,​ ​slot(time(bH,​ ​bM,​ ​bP),​ ​time(eH,​ ​eM,​ ​eP))), bH​ ​*​ ​60​ ​+​ ​bM​ ​=<​ ​endHour​ ​*​ ​60​ ​+​ ​endMinute, eH​ ​*​ ​60​ ​+​ ​eM​ ​>=​ ​beginHour​ ​*​ ​60​ ​+​ ​beginMinute.

main​ ​:-​ ​findall(Person,

meetone(Person,slot(time(8,30,am),time(8,45,am))), People),

write(People), nl, halt.

:-​ ​initialization(main). Meet.pl #!/bin/gprolog​ ​--consult-file :-​ ​include('data.pl'). :-​ ​include('uniq.pl'). %​ ​Your​ ​code​ ​goes​ ​here. meet​ ​:- people([ann,bob,carla]). main​ ​:-​ ​findall(Slot,​ ​meet(Slot),​ ​Slots), ​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​uniq(Slots,​ ​Uniq), ​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​write(Uniq),​ ​nl,​ ​halt. :-​ ​initialization(main).