About 342,000 results
Open links in new tab
  1. python - Algorithm to count unit triangles in large composite shape

    I need to write a brute-force algorithm to count the number of unit triangles in a complex shape. The shape is created each iteration by adding triangles to surround all outer edges. The shape in iteration number n would look as above and the outputs would be 1 4 10 respectively.

  2. Count Possible Triangles - GeeksforGeeks

    Dec 28, 2024 · # Python code to count the number of possible triangles # using Two Pointers Technique def countTriangles (arr): res = 0 arr. sort # Iterate through the array, fixing the largest side at arr[i] for i in range (2, len (arr)): # Initialize pointers for the two smaller sides left, right = 0, i-1 while left < right: if arr [left] + arr [right ...

  3. python - Count all possible triangles - Stack Overflow

    Aug 12, 2019 · Solution 1: use binary search to get O(n^2 log(n)) Pseudo code: for b in B: use binary search to find the highest index c_low in C_s s.t. C_s[c_low] <= |a-b|. use binary search to find lowest index c_high in C_s s.t. C_s[c_high] >= a+b. count += (c_high-c_low-1) Explanation and demonstration of correctness:

  4. Python and the CountTriangles Problem | Reintech media

    Oct 10, 2023 · Learn how to solve the CountTriangles problem using Python. This tutorial covers a comprehensive guide on how to approach and solve this classic computational geometry problem with Python.

  5. smart-interviews-problems/Count the Triangles.py at master ...

    For each test case, print the total number of different triangles possible, separated by new line.

  6. Counting triangles with integer sides - John D. Cook

    Nov 8, 2020 · Exploring the number of triangles with integer sides and a given perimeter. Compute with a recursive Python function.

  7. HackerEarth-solutions/Counting Triangles.py at main · sriahri

    This repository contains solutions to various coding challenges and problems from HackerEarth. Each solution is implemented in Python and/or other programming languages. - sriahri/HackerEarth-solut...

  8. Counting Triangles in Node Graphs with Python

    One day at work with Humanyze, I came across a particularly elegant and mysterious method to count the number of triangles in a node graph (in python). Suppose S is a numpy array of the square matrix representation of an undirected node graph (with no self edges), then.

  9. Triangle counting in Python and Java · GitHub

    def count_triangle(graph): n = 0: for wedge in wedge_iterator(graph): if graph.has_edge(wedge[1][0], wedge[1][1]) or graph.has_edge(wedge[1][1], wedge[1][0]): n += …

  10. CodeChef-Practise-Beginner-Python/D - Triangle Count.py at …

    A short list of Python codes solutions from Codechef/Practice/Beginner. Questions -> - CodeChef-Practise-Beginner-Python/D - Triangle Count.py at master · S-C-U-B-E/CodeChef-Practise-Beginner-Python

  11. Some results have been removed
Refresh