/* Uzbekian puzzle in Picat. From Belaid MOA, "Examples for Discrete Constraint Programming" http://www.docstoc.com/docs/23988870/Examples-for-Discrete-Constraint-Programming page 49f """ An Uzbekian sales man met five traders who live in five different cities. The five traders are: {Abdulhamid, Kurban, Ruza,Sharaf, Usman} The five cities are: {Bukhara, Fergana, Kokand, Samarkand, Tashkent} Find the order in which he visited the cities given the following information. - He met Ruza before Sharaf after visiting Samarkand, - He reached Fergana after visiting Samarkand followed by two other cities - The third trader he med was Tashkent - Immediately after his visit to Bukhara, he met Abdulhamid - He reached Kokand after visiting the city of Kurban followed by two other cities. """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go => NumCities = 5, [Bukhara,Fergana,Kokand,Samarkand,Tashkent] = [1,2,3,4,5], CitiesS = ['Bukhara','Fergana','Kokand','Samarkand','Tashkent'], VisitCity = new_list(NumCities), VisitCity :: 1..NumCities, NumTraders = 5, [Abdulhamid,Kurban,Ruza,Sharaf,_Usman] = [1,2,3,4,5], TradersS = ['Abdulhamid','Kurban','Ruza','Sharaf','Usman'], MeetTrader = new_list(NumTraders), MeetTrader :: 1..NumTraders, all_different(MeetTrader), all_different(VisitCity), % - He met Ruza before Sharaf after visiting Samarkand, MeetTrader[Ruza] #< MeetTrader[Sharaf], MeetTrader[Ruza] #> VisitCity[Samarkand], % - He reached Fergana after visiting Samarkand followed by % two other cities VisitCity[Fergana] #= VisitCity[Samarkand] + 2, % - The third trader he met was Tashkent VisitCity[Tashkent] #= 3, % - Immediately after his visit to Bukhara, he met Abdulhamid MeetTrader[Abdulhamid] #= VisitCity[Bukhara] + 1, % - He reached Kokand after visiting the city of Kurban followed % by two other cities. VisitCity[Kokand] #= MeetTrader[Kurban] + 2, Vars = VisitCity ++ MeetTrader, solve(Vars), println(VisitCity), println(MeetTrader), foreach(I in 1..NumCities) nth(City,VisitCity,I), nth(Trader,MeetTrader,I), printf("Meeting %d was in %w meeting %w\n", I, CitiesS[City],TradersS[Trader]) end, nl, fail, nl.