>>106409330
>https://godbolt.org/z/96q4qn7cK
is crisper than
>>106406915
>https://godbolt.org/z/eW6T5KrTW
hence another point to
>>106406807
>will always run faster
Also, the C version can also be output with the gcc v13.4 instead of clang used in the example above.
Also, this
>>106406623 becomes this
https://godbolt.org/z/bKa9dq5r6
and seems unique, and is likely the most performant, since it skips the useless iterations, which at a quick glance the compiler does seem not to optimize away in the single-increment loops).
(Though "var total" should be "int total" to compile.)
Then there's also the purely arithmetic solution, i.e. there is a formula with which the output can be returned in one or two arithmetic operations.
Some are mentioned here, but I'm too lazy to verify their correctness, you do that.
Instead of realizing all this, they went and created an entire new language instead and are on crusade to rewrite all software in it.
lol.