dmcommunity.org challenge Jun 2021 with #Prolog

My #prolog solution for “Where is gold?” proposed by dmcommunity.org challenge Jun 2021: 0 means empty, 1 means gold ?- solution(Box1,Box2,Box3). Box1 = Box3, Box3 = 0, Box2 = 1. below the code :-use_module(library(clpfd)). sentence1( 1,_Box2,_Box3). not_sentence1(0,_Box2,_Box3). sentence2( _Box1,0,_Box3). not_sentence2(_Box1,1,_Box3). sentence3( 0,_Box2,_Box3). not_sentence3(1,_Box2,_Box3). true_only_one_sentence(Box1, Box2, Box3):- ( sentence1(Box1,Box2,Box3), not_sentence2(Box1,Box2,Box3), not_sentence3(Box1,Box2,Box3) ) ; ( not_sentence1(Box1,Box2,Box3), sentence2(Box1,Box2,Box3), not_sentence3(Box1,Box2,Box3) ) ; ( not_sentence1(Box1,Box2,Box3), not_sentence2(Box1,Box2,Box3), sentence3(Box1,Box2,Box3) ). solution(Box1, Box2, Box3):- Box1 in 0..1, /* 0 empty, 1 gold */ Box2 in 0....

June 2, 2021 · 1 min · 98 words · Matteo Redaelli

dmcommunity.org challenge Feb 2021 with #Prolog

My #swi #prolog solution for “Benchmark ‘Medical Services’” proposed by dmcommunity.org challenge Feb 2021 can be tested running a public docker image docker run -p 8888:8888 -d --name matteoredaelli/dmcommunity_org_2021_02:latest wget https://github.com/DMCommunity/dmcommunity_shared/raw/master/MedicalServices.json curl -XPOST -d @MedicalServices.json -H "Accept: application/json" -H "Content-type: application/json" http://localhost:8888/many The decision table is a set of prolog facts like decision_table('Office','acupuncture','PL123','L','Y','N','2015-01-01','2023-12-31','N','N','N'). decision_table('Outpatient','acupuncture','PL123','L','Y','N','2015-01-01','2023-12-31','N','N','N'). decision_table('Inpatient','acupuncture','PL123','L','N','N','2015-01-01','2023-12-31','N','N','N'). The core of the solution is inside the rules.pl file parse_input(json([placeOfService=PlaceOfService, type=Type, plan=Plan, groupSize=GroupSize, inNetwork=InNetwork, isCovered=IsCovered, dateOfService=DateOfService, coveredInFull=_, copay=_, coInsurance=_]), json([placeOfService=PlaceOfService, type=Type, plan=Plan, groupSize=GroupSize, inNetwork=InNetwork, isCovered=IsCovered, dateOfService=DateOfService, coveredInFull=CoveredInFull, copay=Copay, coInsurance=CoInsurance])):- decision_table(PlaceOfService, Type, Plan, GroupSize, InNetwork, IsCovered, DateOfService1, DateOfService2, CoveredInFull, Copay, CoInsurance), %% check date: must be between the two dates in decision_table atom_string(DateOfService, DateOfServiceString), atom_string(DateOfService1, DateOfService1String), atom_string(DateOfService2, DateOfService2String), DateOfService1String @=< DateOfServiceString, DateOfServiceString @=< DateOfService2String....

February 2, 2021 · 1 min · 141 words · Matteo Redaelli

dmcommunity.org challenge Dec 2020 with #Prolog

Below my #swi #prolog solution for “Virtual Chess tournament” proposed by dmcommunity.org challenge Dec 2020 Player 1 is Fischer, player 2 is Kasparov and player 3 is Karpov. I can find two solutions (Score1,Wins1,Draws1,Loses1 are Fischer’s score, number of wins, draws and loses,..) is: ?- time(solution([[Score1,Wins1,Draws1,Loses1],[Score2,Wins2,Draws2,Loses2],[Score3,Wins3,Draws3,Loses3]])). % 1,297,058 inferences, 0.136 CPU in 0.136 seconds (100% CPU, 9557549 Lips) Score1 = 15, Wins1 = 4, Draws1 = 7, Loses1 = Draws2, Draws2 = 3, Score2 = 13, Wins2 = 5, Loses2 = 6, Score3 = 14, Wins3 = Loses3, Loses3 = 2, Draws3 = 10 ; % 152,142 inferences, 0....

December 7, 2020 · 2 min · 388 words · Matteo Redaelli

dmcommunity.org challenge Nov 2020 with #Prolog

Below my #prolog solution for “Calculator with Two Buttons” proposed by dmcommunity.org challenge Nov 2020 swipl nov2020.pl ?- shortest_path(0,5034,Path), length(Path,Len), findall(Op,member([_,Op,_], Path), Ops). Path = [[0,+,1],[1,+,2],[2,+,3],[3,+,4],[4,+,5],[5,*,50],[50,*,500],[500,+,501],[501,+,502],[502,+,503],[503,*,5030],[5030,+,5031],[5031,+,5032],[5032,+,5033],[5033,+,5034]], Len = 15, Ops = [+,+,+,+,+,*,*,+,+,+,*,+,+,+,+]. Below my nov2020.pl script :- use_module(library(clpfd)). shortest_path(From, To, Path):- From #>= 0, shortest_path(From, To, 0, Path). shortest_path(From, To, MaxDepth, Path):- path(From, To, MaxDepth, Path),! . shortest_path(From, To, MaxDepth, Path):- MaxDepth1 #= MaxDepth + 1, shortest_path(From, To, MaxDepth1, Path). path(From, To, _MaxDepth, [[From, Op, To]]):- step(From, Op, To)....

November 14, 2020 · 1 min · 119 words · Matteo Redaelli

Doctor Planning resolved with #Prolog

Below my #prolog solution for “Doctor Planning” proposed by dmcommunity.org challenge April 2020 There should be more constraints like a limit of shifts a week for each doctor… In any case after few seconds I get the first result [[2,3,4],[2,3,4],[2,3,4],[2,3,4],[1,2,3],[1,2,4],[1,2,4]] It means: Monday sheets: doctor 2 (early), doctor 3 (late) and doctor 4 (night)… :- use_module(library(clpfd)). /* using swi-prolog */ :- use_module(library(clpz)). /* using scryer-prolog */ /* solver for issue https://dmcommunity....

April 22, 2020 · 4 min · 802 words · Matteo Redaelli