The answer is 24, how to get it by GH?
1.gh (2.1 KB)
here is another solution that uses geometry only to define adjacency, the traverses the graph recognizing in-line-nodes as single edges (which I believe is the most pressing issue, or at least it was for me when trying to just traverse the graph )
Python code taken from here: python - Counting triangles in a hexagon - Stack Overflow
1_Re.gh (18.6 KB)
The answer is nine.
P.S. Wait, only five of the fragments from SrfSplit are triangles:
The goal of this thread needs clarification
Took me quite awhile to understand the objective here, and then I finally understood @inno’s solution.
So I started with his code and added a little bit to his Python to output his list of triangles as ‘a’:
trishapes = []
print('--- triangles ---')
for triangle in sorted(triangles):
print(triangle)
trishapes.append(triangle)
a = trishapes
Then I added the purple group to parse that list of points that make each triangle.
Needed this one line of Python to get only the numbers (point indices):
a = filter(str.isdecimal,s)
And finally added List Item to view each triangle, one at a time.
Nice work @inno
P.S. Now I realize that @RadovanG also figured it out. Nice work @RadovanG
Took me awhile to wake up.
well, consider that the whole code comes from the big brains @ stackoverflow, not from mine
the interesting part is indeed to use geometry just to get the initial data, and detaching the problem solving process from any geometry by transforming the whole thing into a graph traversal
also, it’s still a bit vague in my mind how to exactly shatter line AB with points 1, 2, 3 in GH, in such a way to get all the possible segment combinations [A1, 1B, A2, 2B, A3, 3B, 12, 23, 13, … AB] (thing I believe @RadovanG has solved in the first part of his definition, but I didn’t have time to explore yet [edit] oh, seen it now, it’s sort of bruteforce approach by crossreferencing edges, culls duplicate combinations of edge indexes that would result in the same data, and pushes the hard work -to understand if the candidate edges create a tringle- to Curve.CreateBooleanRegions )
it think it mostly depends whether it’s a one-shot well-definite problem, or a solution for a “general case”
I believe the problem you linked can be identified in the class of “coin change problem”, bruteforcing it works while the number you have to reach is “resonable”
but if the problems wants you to list all different combinations to get to something overwhelming, like to 1 million, by summing the numbers [1, 2, 3] then I would drift toward a dynamic programming approach ( https://www.youtube.com/watch?v=H9bfqozjoqs&ab_channel=NeetCode )
in a similar flavor, finding triangles for 7 lines can be solved geometrically and it gives a perfect final solution in a matter of milliseconds, but if you have 15 thousand lines then I’d go for a graph-based approach
Unfortunately, graph theory is missing from my education and experience. I remember the coin change problem, from way back (~52 years!) in my introductory Basic and Fortran classes. That video is good but gets tedious… I stopped watching at 12:20. Thanks.
I use the same Python code shared by @inno with a little modification
I test shapes from these videos:
count triangles.gh (21.3 KB)