Encoding dlv encoding

Name dlv encoding [Root]    Puzzles (51) Martin Gebser dlv encoding of Diamond Puzzle 2009-03-30 13:03 2008-11-29 00:10 No nodiamond_incol(X,Y,Y) :- #int(X), #int(Y), not diamond(X,Y). nodiamond_incol(X,LU,LD) :- nodiamond_incol(X,LU,LD1), #succ(LD1,LD), not diamond(X,LD). nodiamond_incol(X,LU,LD) :- nodiamond_incol(X,LU1,LD), #succ(LU1,LU), not diamond(X,LU). nodiamond_inrow(X,X,Y) :- #int(X), #int(Y), not diamond(X,Y). nodiamond_inrow(LL,LR,Y) :- nodiamond_inrow(LL,LR1,Y), #succ(LR1,LR), not diamond(LR,Y). nodiamond_inrow(LL,LR,Y) :- nodiamond_inrow(LL1,LR,Y), #succ(LL1,LL), not diamond(LL,Y). dsquare_OK(DX,DY,0,0,0,0) :- diamond(DX,DY). dsquare_OK(DX,DY,U,D,L,R) :- dsquare_OK(DX,DY,U1,D,L1,R), #succ(U1,U), #succ(L1,L), DX = LL + L, DY = LU + U, LD = DY + D, LR = DX + R, nodiamond_incol(LL,LU,LD), nodiamond_inrow(LL,LR,LU). dsquare_OK(DX,DY,U,D,L,R) :- dsquare_OK(DX,DY,U1,D,L,R1), #succ(U1,U), #succ(R1,R), DX = LL + L, DY = LU + U, LD = DY + D, LR = DX + R, nodiamond_incol(LR,LU,LD), nodiamond_inrow(LL,LR,LU). dsquare_OK(DX,DY,U,D,L,R) :- dsquare_OK(DX,DY,U,D1,L1,R), #succ(D1,D), #succ(L1,L), DX = LL + L, DY = LU + U, LD = DY + D, LR = DX + R, nodiamond_incol(LL,LU,LD), nodiamond_inrow(LL,LR,LD). dsquare_OK(DX,DY,U,D,L,R) :- dsquare_OK(DX,DY,U,D1,L,R1), #succ(D1,D), #succ(R1,R), DX = LL + L, DY = LU + U, LD = DY + D, LR = DX + R, nodiamond_incol(LR,LU,LD), nodiamond_inrow(LL,LR,LD). dsquare(DX,DY,Hup,Hdown,Hleft,Hright) v ndsquare(DX,DY,Hup,Hdown,Hleft,Hright) :- dsquare_OK(DX,DY,Hup,Hdown,Hleft,Hright). :- #count{ Hup,Hdown,Hleft,Hright: dsquare(DX,DY,Hup,Hdown,Hleft,Hright) } > 1, diamond(DX,DY). :- #count{ Hup,Hdown,Hleft,Hright: dsquare(DX,DY,Hup,Hdown,Hleft,Hright) } < 1, diamond(DX,DY). dsquarecover(DX,DY,X,Y) :- dsquare(DX,DY,Hup,Hdown,Hleft,Hright), X = DX + R, R <= Hright, Y = DY + D, D <= Hdown. dsquarecover(DX,DY,X,Y) :- dsquare(DX,DY,Hup,Hdown,Hleft,Hright), X = DX + R, R <= Hright, DY = Y + U, U <= Hup. dsquarecover(DX,DY,X,Y) :- dsquare(DX,DY,Hup,Hdown,Hleft,Hright), DX = X + L, L <= Hleft, Y = DY + D, D <= Hdown. dsquarecover(DX,DY,X,Y) :- dsquare(DX,DY,Hup,Hdown,Hleft,Hright), DX = X + L, L <= Hleft, DY = Y + U, U <= Hup. :- dsquarecover(DX1,DY1,X,Y), dsquarecover(DX2,DY2,X,Y), DX1 <> DX2. :- dsquarecover(DX1,DY1,X,Y), dsquarecover(DX2,DY2,X,Y), DY1 <> DY2. covered(X,Y) :- dsquarecover(DX,DY,X,Y). :- #int(X), #int(Y), not covered(X,Y).