Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
import cp.
|
||||
|
||||
go =>
|
||||
puzzle(T, X, Y,Z),
|
||||
foreach(TT in T)
|
||||
println(TT)
|
||||
end,
|
||||
println([x=X,y=Y,z=Z]),
|
||||
nl,
|
||||
fail, % are there any more solutions?
|
||||
nl.
|
||||
|
||||
% Port of the Prolog solution
|
||||
puzzle(Ts, X, Y, Z) :-
|
||||
Ts = [ [151],
|
||||
[_, _],
|
||||
[40, _, _],
|
||||
[_, _, _, _],
|
||||
[X, 11, Y, 4, Z]],
|
||||
Y #= X + Z,
|
||||
triangle(Ts),
|
||||
Vs = vars(Ts),
|
||||
Vs :: 0..10000,
|
||||
solve(Vs).
|
||||
|
||||
triangle([T|Ts]) :-
|
||||
( Ts = [N|_] -> triangle_(T, N), triangle(Ts) ; true ).
|
||||
|
||||
triangle_([], _).
|
||||
triangle_([T|Ts],[A,B|Rest]) :-
|
||||
T #= A + B, triangle_(Ts, [B|Rest]).
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
import cp.
|
||||
|
||||
puzzle2 =>
|
||||
N = 5, % number of rows
|
||||
Len = (N*(N+1)) div 2, % number of entries
|
||||
|
||||
% The triangle numbers for 1..N
|
||||
T = [I*(I+1) div 2 : I in 1..N],
|
||||
|
||||
% The index of first number to use in addition
|
||||
% create the indices of the numbers to add,
|
||||
% i.e. Adds[I] + Adds[I+1]
|
||||
Adds = new_list(T[N-1]),
|
||||
Adds[1] := 2,
|
||||
foreach(I in 2..T[N-1])
|
||||
% "jump" of 2 when i-1 is a triangle number
|
||||
if membchk(I-1,T) then
|
||||
Adds[I] := Adds[I-1] + 2
|
||||
else
|
||||
Adds[I] := Adds[I-1] + 1
|
||||
end
|
||||
end,
|
||||
|
||||
% the pyramid
|
||||
MaxVal = 10_000,
|
||||
L = new_list(Len),
|
||||
L :: 1..MaxVal,
|
||||
|
||||
% The clues.
|
||||
L = [ 151,
|
||||
_, _,
|
||||
40, _, _,
|
||||
_, _,_ , _ ,
|
||||
X, 11, Y, 4, Z
|
||||
],
|
||||
|
||||
% The sums
|
||||
foreach(I in 1..T[N-1])
|
||||
L[I] #= L[Adds[I]]+L[Adds[I]+1]
|
||||
end,
|
||||
|
||||
% The extra constraint
|
||||
Y #= X + Z,
|
||||
|
||||
solve(L),
|
||||
println([x=X,y=Y,z=Z]),
|
||||
fail, % check if there is another solution
|
||||
nl.
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
import cp.
|
||||
|
||||
puzzle3 =>
|
||||
% 1
|
||||
% 2 3
|
||||
% 4 5 6
|
||||
% 7 8 9 10
|
||||
%11 12 13 14 15
|
||||
|
||||
X = new_list(15),
|
||||
X :: 0..10_000,
|
||||
X[1] #= X[2]+X[3],
|
||||
X[2] #= X[4]+X[5],
|
||||
X[3] #= X[5]+X[6],
|
||||
X[4] #= X[7]+X[8],
|
||||
X[5] #= X[8]+X[9],
|
||||
X[6] #= X[9]+X[10],
|
||||
X[7] #= X[11]+X[12],
|
||||
X[8] #= X[12]+X[13],
|
||||
X[9] #= X[13]+X[14],
|
||||
X[10] #= X[14]+X[15],
|
||||
X[13] #= X[11] + X[15], % Y=X+Z,
|
||||
|
||||
% The hints
|
||||
X[1] #= 151,
|
||||
X[4] #= 40,
|
||||
X[12] #= 11,
|
||||
X[14] #= 4,
|
||||
|
||||
solve(X),
|
||||
println([x=X[11],y=X[13],z=X[15]]),
|
||||
fail,
|
||||
nl.
|
||||
Loading…
Add table
Add a link
Reference in a new issue