A couple of days ago I made a "combinations" function in #C that works the same as #Python itertools.combinations. I used it to help with a #Numberphile challenge, however I misunderstood: duplicates WERE allowed. So I binned it all, went back to nested loops and added multi-threading. Now it only takes about 0.01 s to calculate all #tetrahedral sums (up to 5 terms) of 343867 which is supposed to be the last one that requires more than 4 terms.

Works on #Mac and #Linux: https://github.com/ednl/tetrahedral/blob/main/tetrasum.c

tetrahedral/tetrasum.c at main ยท ednl/tetrahedral

Pollock's conjecture: any integer can be written as a sum of at most five tetrahedral numbers. - ednl/tetrahedral

GitHub
โ€ฆ or other numbers! The program is not specifically geared towards confirming or disproving the conjecture, but it can analyse every number between 0 and 2^32. Just add the number on the command line: e.g. "tetrasum -q 10000001" outputs 92 sums of tetrahedral numbers with up to four terms and counts another 5592 sums with five terms.

It took a little under 3 hours for my program on a #RaspberryPi 5 with 4 cores at 2.4 GHz to calculate that there are 863 #tetrahedral sums of up to 4 terms for the number 2^32-1, and another 377968 sums of 5 terms.

#programming #C #Clanguage #C_lang #mathematics #maths #math #numberphile #JournalOfRecreationalMathematics #compsci #PollocksConjecture

There were a few data races that I missed but I fixed it. The results are still the same for all numbers I checked, so apparently the potential race conditions didn't corrupt the data. Also a bit faster now without binary search for the fifth term. https://github.com/ednl/c/blob/master/tetrasum.c
c/tetrasum.c at master ยท ednl/c

C language programs, files and projects. Contribute to ednl/c development by creating an account on GitHub.

GitHub
P.S.: the "combinations()" iterator function in C is now at https://github.com/ednl/c/blob/master/combinations.c (and you will also need the .h header file in the same dir).
c/combinations.c at master ยท ednl/c

C language programs, files and projects. Contribute to ednl/c development by creating an account on GitHub.

GitHub
@ednl out of curiosity, why on a Pi?
@Zamfr Because it is the Linux computer I have. And it is an easy reference; if I say "it runs in 10 mins on my PC" then I have to list all the specs of the PC before that means anything. If I say "RPi 5" then it's immediately clear what I'm talking about.
@ednl ha dat klinkt logisch. Ik zat te puzzelen, is er iets wat een rpi5 hier heel geschikt voor maakt?
@Zamfr Oh ha ha, nee, hij staat hier gewoon. Heb het ook net geprobeerd op een Mac Mini M1: 59 minuten.