You have N sticks with lengths 1, 2, 3, ..., N.
Provide a closed form function in terms of N for the number of distinct valid triangles can you make from these N sticks.
note: reflections and rotations are considered to be the same, and valid triangles must have positive area.
Inspired by 5, 6, Pick Up Sticks
((2*N-3)*(N-1)*(N-2)/6-floor((N-1)/2))/4
from Jerry W. Lewis's formula under OEIS's A002623, adjusted for a different offset.
clearvars
ctList=[];
for N=3:25
ct=0;
sticksets=combinator(N,3,'c');
for i=1:size(sticksets,1)
tri=sticksets(i,:);
if sum(tri)-max(tri)>max(tri)
ct=ct+1;
end
end
fprintf('%3d %10d %10d\n',N,ct,((2*N-3)*(N-1)*(N-2)/6-floor((N-1)/2))/4);
ctList(end+1)=ct;
end
fprintf('%d, ',ctList)
fprintf('\n')
produces
N triangles closed formula
3 0 0
4 1 1
5 3 3
6 7 7
7 13 13
8 22 22
9 34 34
10 50 50
11 70 70
12 95 95
13 125 125
14 161 161
15 203 203
16 252 252
17 308 308
18 372 372
19 444 444
20 525 525
21 615 615
22 715 715
23 825 825
24 946 946
25 1078 1078
0, 1, 3, 7, 13, 22, 34, 50, 70, 95, 125, 161, 203, 252, 308, 372, 444, 525, 615, 715, 825, 946, 1078,
The bottom set was produced by the original program without the formula, for input to the OEIS, to identify the sequence.
|
Posted by Charlie
on 2025-05-27 09:37:45 |