algus(q0). ots(q3). seos(q0, q1, 1). seos(q1, q0, 1). seos(q1, q3, 0). %seos(q3, q1, 0). kahene():- algus(X), seos(X, Y, A), seos(Y, _, B), write(A), writeln(B), false. %Kuvage kõik neljasammulised sõnad %püüdke ehitada skeem selliselt, et aktsepteeritavaid %neljasammulisi sõnu oleks kaks tükki neljane():- algus(X), seos(X, Y, A), seos(Y, Z, B), seos(Z, V, C), seos(V, _, D), write(A), write(B), write(C), writeln(D), false. neljane2(A, B, C, D):- algus(X), seos(X, Y, A), seos(Y, Z, B), seos(Z, V, C), seos(V, _, D). eesnimi --> [juku]. eesnimi --> [kati]. tervitussona --> [tere]. tervitussona --> [ahoi]. %tervitussona --> tervitussona, [tere]. tervitus --> tervitussona, eesnimi. qS --> [a], qB. qS --> [b], qA. qA --> [a]. qA --> [a], qS. qA --> [b], qA, qA. qB --> [b]. qB --> [b], qS. qB --> [a], qB, qB. ______________ Search Login with GoogleLogin with StackOverflow 52 Program algus(q0). ots(q3). seos(q0, q1, 1). seos(q1, q0, 1). seos(q1, q3, 0). %seos(q3, q1, 0). kahene():- algus(X), seos(X, Y, A), seos(Y, _, B), write(A), writeln(B), false. %Kuvage kõik neljasammulised sõnad %püüdke ehitada skeem selliselt, et aktsepteeritavaid %neljasammulisi sõnu oleks kaks tükki neljane():- algus(X), seos(X, Y, A), seos(Y, Z, B), seos(Z, V, C), seos(V, _, D), write(A), write(B), write(C), writeln(D), false. neljane2(A, B, C, D):- algus(X), seos(X, Y, A), seos(Y, Z, B), seos(Z, V, C), seos(V, _, D). eesnimi --> [juku]. eesnimi --> [kati]. tervitussona --> [tere]. tervitussona --> [ahoi]. %tervitussona --> tervitussona, [tere]. tervitus --> tervitussona, eesnimi. qS --> [a], qB. qS --> [b], qA. qA --> [a]. qA --> [a], qS. qA --> [b], qA, qA. qB --> [b]. qB --> [b], qS. qB --> [a], qB, qB. 1 ​ 2 algus(q0). 3 ots(q3). 4 seos(q0, q1, 1). 5 seos(q1, q0, 1). 6 seos(q1, q3, 0). 7 %seos(q3, q1, 0). 8 ​ 9 kahene():- 10 algus(X), seos(X, Y, A), seos(Y, _, B), 11 write(A), writeln(B), false. 12 ​ 13 %Kuvage kõik neljasammulised sõnad 14 %püüdke ehitada skeem selliselt, et aktsepteeritavaid 15 %neljasammulisi sõnu oleks kaks tükki 16 ​ 17 neljane():- 18 algus(X), seos(X, Y, A), seos(Y, Z, B), 19 seos(Z, V, C), seos(V, _, D), 20 write(A), write(B), write(C), writeln(D), false. 21 ​ 22 neljane2(A, B, C, D):- 23 algus(X), seos(X, Y, A), seos(Y, Z, B), 24 seos(Z, V, C), seos(V, _, D). 25 ​ 26 ​ 27 eesnimi --> [juku]. 28 eesnimi --> [kati]. 29 ​ 30 tervitussona --> [tere]. 31 tervitussona --> [ahoi]. 32 %tervitussona --> tervitussona, [tere]. 33 tervitus --> tervitussona, eesnimi. 34 ​ 35 ​ 36 qS --> [a], qB. 37 qS --> [b], qA. 38 qA --> [a]. 39 qA --> [a], qS. 40 qA --> [b], qA, qA. 41 qB --> [b]. 42 qB --> [b], qS. 43 qB --> [a], qB, qB. 44 ​ 45 ​ algus(X), seos(X, Y, A), seos(Y, Z, B). A = B, B = 1, X = Z, Z = q0, Y = q1 algus(X), seos(X, Y, A), seos(Y, Z, B). A = B, B = 1, X = Z, Z = q0, Y = q1 A = 1, B = 0, X = q0, Y = q1, Z = q3 algus(X), seos(X, Y, A), seos(Y, Z, B), ots(Z). A = 1, B = 0, X = q0, Y = q1, Z = q3 kahene(). functor/3: Domain error: `compound_non_zero_arity' expected, found `kahene()' kahene(). functor/3: Domain error: `compound_non_zero_arity' expected, found `kahene()' kahene(). functor/3: Domain error: `compound_non_zero_arity' expected, found `kahene()' kahene(). functor/3: Domain error: `compound_non_zero_arity' expected, found `kahene()' kahene. q3false kahene. 10false kahene. Singleton variables: [Z] 1110false kahene. Singleton variables: [Z] 11 10 false kahene. 11 10 false neljane. Singleton variables: [A,B,C,W,D] Singleton variables: [A,B,C,D] Full stop in clause-body? Cannot redefine ,/2 1true neljane. Singleton variables: [W] 11111110false neljane. Singleton variables: [W] 1111 1110 false neljane2(A, B, C, D). Singleton variables: [W] Singleton variables: [W] A = B, B = C, C = D, D = 1 neljane2(A, B, C, D). Singleton variables: [W] A = B, B = C, C = D, D = 1 A = B, B = C, C = 1, D = 0 A=1, B=0, C=1, D=0, neljane2(A, B, C, D). Singleton variables: [W] false A=1, B=1, C=1, D=0, neljane2(A, B, C, D). Singleton variables: [W] A = B, B = C, C = 1, D = 0 A=1, B=1, C=1, D=0, neljane2(A, B, C, D). A = B, B = C, C = 1, D = 0 false phrase(tervitus, A, B). A = [tere, juku|B] A = [tere, kati|B] A = [ahoi, juku|B] A = [ahoi, kati|B] A = [tere, tere, juku|B] A = [tere, tere, kati|B] A = [ahoi, tere, juku|B] A = [ahoi, tere, kati|B] A = [tere, tere, tere, juku|B] A = [tere, tere, tere, kati|B] A = [ahoi, tere, tere, juku|B] phrase(tervitus, tere , juku). Stack limit (0.2Gb) exceeded Stack sizes: local: 0.2Gb, global: 19.6Mb, trail: 2Kb Stack depth: 2,567,626, last-call: 0%, Choice points: 12 In: [2,567,626] tervitussona(tere, _1702) [2,567,625] tervitussona(tere, _1728) [2,567,624] tervitussona(tere, _1754) [2,567,623] tervitussona(tere, _1780) [2,567,622] tervitussona(tere, _1806) Use the --stack_limit=size[KMG] command line option or ?- set_prolog_flag(stack_limit, 2_147_483_648). to double the limit. phrase(tervitus, [tere, juku]). 1true Stack limit (0.2Gb) exceeded Stack sizes: local: 0.2Gb, global: 19.6Mb, trail: 0Kb Stack depth: 2,568,045, last-call: 0%, Choice points: 12 In: [2,568,045] tervitussona([length:2], _1440) [2,568,044] tervitussona([length:2], _1472) [2,568,043] tervitussona([length:2], _1504) [2,568,042] tervitussona([length:2], _1536) [2,568,041] tervitussona([length:2], _1568) Use the --stack_limit=size[KMG] command line option or ?- set_prolog_flag(stack_limit, 2_147_483_648). to double the limit. phrase(tervitus, [tere, mati]). Stack limit (0.2Gb) exceeded Stack sizes: local: 0.2Gb, global: 19.6Mb, trail: 2Kb Stack depth: 2,567,627, last-call: 0%, Choice points: 12 Probable infinite recursion (cycle): [2,567,627] tervitussona([length:2], _1714) [2,567,626] tervitussona([length:2], _1746) phrase(tervitus, [tere, X]). X = juku X = kati Stack limit (0.2Gb) exceeded Stack sizes: local: 0.2Gb, global: 19.6Mb, trail: 0Kb Stack depth: 2,567,999, last-call: 0%, Choice points: 12 Probable infinite recursion (cycle): [2,567,999] tervitussona([length:2], _1440) [2,567,998] tervitussona([length:2], _1472) phrase(tervitus, [tere, X]). X = juku X = kati phrase(qS, Vastus). procedure `a(A,B)' does not exist Reachable from: qS(A,B) phrase(qS, Vastus, Vastus2). procedure `a(A,B)' does not exist Reachable from: qS(A,B) phrase(qS, [X, Y]). procedure `a(A,B)' does not exist Reachable from: qS(A,B) phrase(eesnimi, [X, Y]). false phrase(eesnimi, [X]). X = juku X = kati phrase(qS, [X]). procedure `a(A,B)' does not exist Reachable from: qS(A,B) phrase(qS, [X]). false phrase(qS, [X, Y]). X = a, Y = b X = b, Y = a false phrase(qS, L). L = [a, b] L = [a, b, a, b] L = [a, b, a, b, a, b] L = [a, b, a, b, a, b, a, b] L = [a, b, a, b, a, b, a, b, a, b] phrase(qS, L), length(L, 6). L = [a, b, a, b, a, b] ** Execution aborted ** phrase(qS, L), length(L, 6). L = [a, b, a, b, a, b] ** Execution aborted ** phrase(qS, L), length(L, P), P<=6. Cannot run query due to a syntax error (check query window) phrase(qS, L), length(L, P), member(B, [2, 4, 6]). B = P, P = 2, L = [a, b] B = 4, L = [a, b], P = 2 B = 6, L = [a, b], P = 2 B = 2, L = [a, b, a, b], P = 4 B = P, P = 4, L = [a, b, a, b] B = 6, L = [a, b, a, b], P = 4 B = 2, L = [a, b, a, b, a, b], P = 6 B = 4, L = [a, b, a, b, a, b], P = 6 B = P, P = 6, L = [a, b, a, b, a, b] B = 2, L = [a, b, a, b, a, b, a, b], P = 8 B = 4, L = [a, b, a, b, a, b, a, b], P = 8 B = 6, L = [a, b, a, b, a, b, a, b], P = 8 B = 2, L = [a, b, a, b, a, b, a, b, a, b], P = 10 B = 4, L = [a, b, a, b, a, b, a, b, a, b], P = 10 B = 6, L = [a, b, a, b, a, b, a, b, a, b], P = 10 B = 2, L = [a, b, a, b, a, b, a, b, a, b, a, b], P = 12 B = 4, L = [a, b, a, b, a, b, a, b, a, b, a, b], P = 12 phrase(qS, L), length(L, P), member(P, [2, 4, 6]). L = [a, b], P = 2 ** Execution aborted ** phrase(qS, L), length(L, P), member(P, [2, 4, 6]). L = [a, b], P = 2 L = [a, b, a, b], P = 4 L = [a, b, a, b, a, b], P = 6 ** Execution aborted ** L=[a, b, b, a], phrase(qS, L). L = [a, b, b, a] false L=[a, b, X, Y], phrase(qS, L). L = [a, b, a, b], X = a, Y = b L = [a, b, b, a], X = b, Y = a false L=[X, Y, Z, Q, V, W], phrase(qS, L). L = [a, b, a, b, a, b], Q = W, W = Y, Y = b, V = X, X = Z, Z = a L = [a, b, a, b, b, a], Q = V, V = Y, Y = b, W = X, X = Z, Z = a L = [a, b, a, a, b, b], Q = X, X = Z, Z = a, V = W, W = Y, Y = b L = [a, b, b, a, a, b], Q = V, V = X, X = a, W = Y, Y = Z, Z = b L = [a, b, b, a, b, a], Q = W, W = X, X = a, V = Y, Y = Z, Z = b L = [a, b, b, b, a, a], Q = Y, Y = Z, Z = b, V = W, W = X, X = a L = [a, a, b, b, a, b], Q = W, W = Z, Z = b, V = X, X = Y, Y = a L = [a, a, b, b, b, a], Q = V, V = Z, Z = b, W = X, X = Y, Y = a L = [a, a, b, a, b, b], Q = X, X = Y, Y = a, V = W, W = Z, Z = b L = [a, a, b, a, b, b], Q = X, X = Y, Y = a, V = W, W = Z, Z = b L = [a, a, b, b, a, b], Q = W, W = Z, Z = b, V = X, X = Y, Y = a L = [a, a, a, b, b, b], Q = V, V = W, W = b, X = Y, Y = Z, Z = a L = [b, a, a, b, a, b], Q = W, W = X, X = b, V = Y, Y = Z, Z = a L = [b, a, a, b, b, a], Q = V, V = X, X = b, W = Y, Y = Z, Z = a L = [b, a, a, a, b, b], Q = Y, Y = Z, Z = a, V = W, W = X, X = b L = [b, a, b, a, a, b], Q = V, V = Y, Y = a, W = X, X = Z, Z = b L = [b, a, b, a, b, a], Q = W, W = Y, Y = a, V = X, X = Z, Z = b L = [b, a, b, b, a, a], Q = X, X = Z, Z = b, V = W, W = Y, Y = a L = [b, b, a, a, a, b], Q = V, V = Z, Z = a, W = X, X = Y, Y = b L = [b, b, a, a, b, a], Q = W, W = Z, Z = a, V = X, X = Y, Y = b L = [b, b, a, b, a, a], Q = X, X = Y, Y = b, V = W, W = Z, Z = a L = [b, b, a, a, b, a], Q = W, W = Z, Z = a, V = X, X = Y, Y = b L = [b, b, a, b, a, a], Q = X, X = Y, Y = b, V = W, W = Z, Z = a L = [b, b, b, a, a, a], Q = V, V = W, W = a, X = Y, Y = Z, Z = b L=[_, _, _, _, _, _], phrase(qS, L). L = [a, b, a, b, a, b] L = [a, b, a, b, b, a] L = [a, b, a, a, b, b] L = [a, b, b, a, a, b] L = [a, b, b, a, b, a] L = [a, b, b, b, a, a] L = [a, a, b, b, a, b] L = [a, a, b, b, b, a] L = [a, a, b, a, b, b] L = [a, a, b, a, b, b] L = [a, a, b, b, a, b] L = [a, a, a, b, b, b] L = [b, a, a, b, a, b] L = [b, a, a, b, b, a] L = [b, a, a, a, b, b] L = [b, a, b, a, a, b] L = [b, a, b, a, b, a] L = [b, a, b, b, a, a] L = [b, b, a, a, a, b] L = [b, b, a, a, b, a] L = [b, b, a, b, a, a] L = [b, b, a, a, b, a] L = [b, b, a, b, a, a] L = [b, b, b, a, a, a] %Leidke kõik arvud, mis vastavad valemile a*a+7 %ja on väiksemad sajast ruut2(A, B):- between(1, 9, A), between(1, 9, B), 10 is A+B. ruut4(A, B, C, D):- between(1, 9, A), between(1, 9, B), between(1, 9, C), between(1, 9, D), S=10, S is A+B, S is C+D, S is A+C, S is B+D. %3X3 maagiline ruut, kus ridade ja veergude summaks %on etteantud arv (nt. 10) %Täitke ruudus võimalikult vähe numbreid nõnda %et vastus oleks üheselt määratav ruut3(A, B, C, D, E, F, G, H, I):- between(1, 9, A), between(1, 9, B), between(1, 9, C), between(1, 9, D), between(1, 9, E), between(1, 9, F), between(1, 9, G), between(1, 9, H), between(1, 9, I), S=10, S is A + B + C, S is D + E + F, S is G + H + I, S is A + D + G, S is B + E + H, S is C + F + I. 1 2 X X X 2 X 4 X :- use_module(library(clpfd)). sudoku(Rows) :- length(Rows, 9), maplist(same_length(Rows), Rows), append(Rows, Vs), Vs ins 1..9, maplist(all_distinct, Rows), transpose(Rows, Columns), maplist(all_distinct, Columns), Rows = [As,Bs,Cs,Ds,Es,Fs,Gs,Hs,Is], blocks(As, Bs, Cs), blocks(Ds, Es, Fs), blocks(Gs, Hs, Is). blocks([], [], []). blocks([N1,N2,N3|Ns1], [N4,N5,N6|Ns2], [N7,N8,N9|Ns3]) :- all_distinct([N1,N2,N3,N4,N5,N6,N7,N8,N9]), blocks(Ns1, Ns2, Ns3). sisend(2, L):- L=[ [7, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, 6, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, 8, _, _, _, _, _], [_, _, _, _, _, 3, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _], [_, _, _, _, _, _, _, _, _] ]. sisend(2, Rows), sudoku(Rows), maplist(label, Rows), maplist(portray_clause, Rows).