One day, a customer bought four items at a 711 store. The cashier said:
"That will be $7.11, please."
"Is it $7.11 because this is a 711 store?"
"No, I multiplied the prices together and got $7.11."
"But you are supposed to add them, not multiply them."
"Oh, you’re right! Let me recalculate … that will be $7.11."
What were the four prices? (No rounding)
| Duration | Topic |
|---|---|
| 2 weeks | Propositional & First Order Logic |
| 5 weeks | Logic Programming: the Prolog programming language |
| 5 weeks | CLPFD: Constraint Logic Programming (on Finite Domains) |
| 2 weeks | Description Logics for Semantic Web |
has_gp(GC, GP) :-
has_p(GC, P),
has_p(P, GP).
% GC has grandparent GP if
% GC has parent P and
% P has parent GP.
1+1 is a tree structure,
not evaluated to 2 by default
prime(P) :-
integer(P), P > 1,
P1 is P-1,
\+
(
between(2, P1, I),
P mod I =:= 0
).
% P is a prime if
% P is an integer and P > 1 and
% P1 = P-1 and
% it is not the case that
% ( there exists an I such that:
% 2 =< I =< P1 and
% P is divisible by I
% ).
X is Expr is a built-in predicate (BIP):
art(A, R, T) :-
domain([A,R,T], 0, 9), % A, R and T are digits
A #> 0, R #> 0, % A and R can not be 0
all_distinct([A,R,T]), % A, R and T are all different
(10*A + T) + (100*R + 10*A + T) #= (100*A + 10*R + T).
→
R = 8, A = 9, T = 0
problem711(Vs) :-
Vs = [A,B,C,D], % prices of the 4 items
domain(Vs, 1, 711), % prices are in cents
A+B+C+D #= 711, % prices add up to 711 cents
% A*B*C*D/100^4 = 711/100, % prices in $s multiply to 7.11
A*B*C*D #= 711*100^3, % multiply both sides by 100^4
A #=< B, B #=< C, C #=< D, % increasing order
labeling([ff], Vs). % search