/* Office Blocked problem in Picat. From http://l4f.cecs.anu.edu.au/puzzles/beginner/office-blocked """ Six hardworking employees of the Paper Circulation Division of the Department of Miscellania occupy offices on two floors of the Administration Building: three on the upper floor (offices U1, U2 and U3) and the other three directly below them on the lower floor (L1, L2 and L3): [ floor representation 2 U1 U2 U3 4 5 6 1 L1 L2 L3 1 2 3 ] - Arthur is directly above Bella, who works next to Duncan. - Elizabeth’s office number is smaller than Francesca’s. - Craig and Francesca are in adjacent rooms. Who works where? """ This Picat model was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import cp. main => go. go ?=> Floors = 2, Rooms = 3, N = Floors*Rooms, People = [Arthur,Bella,Craig,Duncan,Elizabeth,Francesca], People = 1..People.len, PeopleS = [ "arthur ", "bella ", "craig ", "duncan ", "elizabeth", "francesca" ], % decision variables Floor = new_list(N), Floor :: 1..Floors, Room = new_list(N), Room :: 1..Rooms, % ensure different rooms all_different($[(Floor[I]-1)*Rooms + Room[I] : I in 1..N]), % - Arthur is directly above Bella, who works next to Duncan. Floor[Arthur] #= 2, Floor[Bella] #= 1, Room[Arthur] #= Room[Bella], Floor[Bella] #= Floor[Duncan], abs(Room[Bella]-Room[Duncan]) #= 1, % - Elizabeth’s office number is smaller than Francesca’s. Room[Elizabeth] #< Room[Francesca], % - Craig and Francesca are in adjacent rooms. Floor[Craig] #= Floor[Francesca], abs(Room[Craig]-Room[Francesca]) #= 1, Vars = Floor ++ Room, solve(Vars), println(floor=Floor), println('room '=Room), println(' '=[(Floor[I]-1)*Rooms + Room[I] : I in 1..N]), foreach(F in 1..Floors) println([PeopleS[P] : R in 1..Rooms, P in 1..N, Room[P] == R, Floor[P] == 3-F]) end, nl, fail, nl. go => true.