:- use_module(library(clpfd)).

q1(D1,D2) :- D1 in 0..9, D2 in 0..9.

q2(D1,D2) :-
	q1(D1,D2),
	D1+D2 #= 10.

% reduces search space from 100 to 81 possibilities
% D1 and D2 cannot be 0.

q3(D1,D2) :-
	q2(D1,D2),
	D1*D2 #>= 24.

% reduces search space to 9 possibilities
% D1 and D2 must be between 4 and 6

q4(D1,D2) :-
	q3(D1,D2),
	D1 #< D2.

% reduces search space to 4 possibilities
% D1 must be 4 or 5, and D2 must be 5 or 6
% it does not find unique solution D1=4 D2=6

q(D1,D2) :-
	D1 in 0..9, D2 in 0..9,
	D1+D2 #= 10,
	D1*D2 #>= 24,
	D1 #< D2.

% You can enter constraints in any order:
% computation is deterministic with no failures.
