My goal is to loop through the list 'vertices' and for each vertex point, it will add the x value to variable C_x, and the y value to variable C_y. Essentially I'm finding the centroid of the polygon, as you can see in the function/procedure's name.
Time complexity and speed is extremely important in my program.
Both versions have O(n) time complexity, and the vertices list is always small with a max of 12 values.
After careful testing there's mixed results, but it seems like combine(map()) has been working better.
I know I probably wrote too much for such a simple question, but any answer I get will help facilitate optimization and efficiency for the rest of my code so help is greatly appreciated.
(Can't embed images for some reason, gonna reply to this post with the images.)
If you're just wanting to add up a list of numbers, by far the fastest way is to use the (sum (numbers)) . You can get this by dragging a reporter onto the arrows of (() + () @<:>) . Here it is in action.
However since you're adding up a list of points, each item being a list of 2 numbers, you may not think that this method will work. Let me introduce to you the incredible concept called hyperblocks.
Hyperblocks allow you to add each item in a list together and get a list back.
Since each point is a 2 item list, you can just add each point together, you don't even have to compute them separately, in fact, you can just add up the entire list of points.
They were just exploring the options available. Combine is still very useful. Don't get on them for using that block, since there's nothing wrong with it. And as they said, that was the fastest method they could find.
Honestly I don't know why I said that anymore, sorry. Well, anyway, they did explain why they were using it, it was the fastest method they could find.