Pascal Triangle

I did a quick and dirty algorithm to find the closest pair of points, I initally allocated a huge block of memory to log all the pairs because I couldn’t figure out what the correct allocation was.

After a slight face palm moment I realized it’s just a pascal triangle. (n(n + 1) / 2) will give me how many pairs are needed.

#include <stdlib.h>


struct obj {
        float pt[2];
};


struct pt_pairs {
        int a;
        int b;
        float dist;
};


int
main() {
        int o_count = 1024;
        struct objs *objs = malloc(sizeof(*objs) * o_count);

        int c_count = ((o_count * (o_count + 1)) / 2);
        struct pt_pairs *pairs(sizeof(*pairs) * c_count);

        /* fill data and calculate distances */
        
        return 0;
}