Toggle navigation
?
users online
Logout
Open hangout
Open chat for current file
% Finds the assignments of 1..9 for A..I such that: % A-B=C % * % D/E=F % = % G+H=I naive_solution(Vars) :- % Enumerate all possible permutations of 1..9 length(Vars, 9), permutation([1,2,3,4,5,6,7,8,9], Vars), Vars = [A,B,C,D,E,F,G,H,I], % Check whether the equations hold for a permutation C is A - B, % First row F is D / E, % Second row I is G + H, % Third row I is C * F. % Column :- use_module(library(clpfd)). % Finds the assignments of 1..9 for A..I such that: % A-B=C % * % D/E=F % = % G+H=I constraint_logic_solution(Vars) :- % The variables are some permutation of 1..9 Vars = [A, B, C, D, E, F, G, H, I], Vars ins 1..9, all_distinct(Vars), % Introduce the grid constraints A - B #= C, % First row D #= E * F, % Second row G + H #= I, % Third row C * F #= I, % Column % Evaluate the constraints label(Vars).