Combinatorial Geometry Algorithm (synthetic) I created an algorithm to solve in synthetic geometry. This problem states that these points are a scalar (real) number. The goal is to first make the possible triangles from the line segments. Then sum up the points within the triangles. For this question, ordering does not matter within the triangle.
I would like to know if there are any improvements possible on the algorithm. For example, if there is a Las Vegas Algorithm for it.
Also, I would like to know if I should make classes or is this even less maintainable than using built-in data structures.


&quot;&quot;&quot;

Triangle sums module

module fn
make_triangles(the_lines: [(float, float)]) -&gt; [(float, float, float)]
total_triangles(the_triangles: [(float, float, float)]) -&gt; [float]
user_output(the_sums: [float]) -&gt; None

&quot;&quot;&quot;


&quot;&quot;&quot;
Problem

Given:
    Our points are made of a single float
    These points are made into tuples within a list
Find:
    the triangles within the points
    The sum of the points on the triangle

Note: the triangles have no distinct ordering in the points
&quot;&quot;&quot;


def make_triangles(the_lines: [(float, float)]) -&gt; [(float, float, float)]:
    &quot;&quot;&quot;
    :param the_lines: the lines to make triangles from
    :return: the triangles
    time: O(len(the_lines) * len(the_lines)
    space: O(len(the_lines) * len(the_lines))
    &quot;&quot;&quot;
    the_triangles: [(float, float, float)] = []
    for pair_a in the_lines:
        for pair_b in the_lines:
            if pair_a == pair_b:
                continue
            if pair_a[0] == pair_b[0]:
                the_triangles.append((pair_a[0], pair_a[1], pair_b[1]))
            elif pair_a[0] == pair_b[1]:
                the_triangles.append((pair_a[0], pair_a[1], pair_b[0]))
    return the_triangles


def total_triangles(the_triangles: [(float, float, float)]) -&gt; [float]:
    &quot;&quot;&quot;
    :param the_triangles: the triangles of points to add up
    :return: a list of the totals
    time: O(len(the_triangles))
    space: O(len(the_triangles))
    &quot;&quot;&quot;
    vec: [float] = [0.0] * len(the_triangles)
    for row in range(len(vec)):
        vec[row] = the_triangles[row][0] + the_triangles[row][1] + the_triangles[row][2]
    return vec


def user_output(the_sums: [float]) -&gt; None:
    &quot;&quot;&quot;
    :param the_sums: the calculated sums
    :return: None
    Output: std output
    &quot;&quot;&quot;
    row = 0
    for number in the_sums:
        if row % 3 == 0:
            print('', end='\n')
        print(str(number), end=&quot; &quot;)
        row = row + 1
    print('\n', end='')


def main() -&gt; None:
    &quot;&quot;&quot;
    Entry point for script
    :return: None
    Input: None
    Output: std output
    &quot;&quot;&quot;
    the_lines = [(0.0, 1.0), (1.0, 2.0), (2.0, 3.0)]
    the_triangles = make_triangles(the_lines)
    the_sums = total_triangles(the_triangles)
    user_output(the_sums)


if __name__ == &quot;__main__&quot;:
    main()





 ```
Here's my attempt at trimming it down. Note that there's no real reason to prefix variables with the_. Also list comprehensions can help with making code more concise, removing the need for total_triangles() entirely.
def make_triangles(lines: [(float, float)]) -&gt; [(float, float, float)]:
    &quot;&quot;&quot;
    :param lines: the lines to make triangles from
    :return: the triangles
    time: O(len(lines) * len(lines)
    space: O(len(lines) * len(lines))
    &quot;&quot;&quot;
    triangles: [(float, float, float)] = []
    for ax, ay in lines:
        for bx, by in lines:
            if ax == bx and ay != by:
                triangles.append((ax, ay, by))
            if ax == by and ax != bx:
                triangles.append((ax, ay, bx))
    return triangles


def print_sums(sums: [float]) -&gt; None:
    &quot;&quot;&quot;
    :param the_sums: the calculated sums
    :return: None
    Output: std output
    &quot;&quot;&quot;
    row = 0
    for number in sums:
        if row % 3 == 0:
            print('', end='\n')
        print(str(number), end=&quot; &quot;)
        row = row + 1
    print('\n', end='')


def main() -&gt; None:
    &quot;&quot;&quot;
    Entry point for script
    :return: None
    Input: None
    Output: std output
    &quot;&quot;&quot;
    lines = [(0.0, 1.0), (1.0, 2.0), (2.0, 3.0)]
    triangles = make_triangles(lines)
    sums = [ sum(triangle) for triangle in triangles ]
    print_sums(sums)


if __name__ == &quot;__main__&quot;:
    main()