> Now, this is a time-memory tradeoff, but my time on this earth is limited so I decided to meta-program the if statements using a programmer program in a different programming language. for i in range(2*8): if i % 2 == 0: No comment...
4 billion if statements (2023)
71–80 of 183 posts
Re: 4 billion if statements (2023)
#72This could be obviously done with much less code: Just add "if"s for all even number, and at the end just return "odd" if none of the evens matched. 50% less code! Or even simpler: If it's 0, return "even". If not, do a recursive call to n-1, if that equals "even", return "odd", otherwise return "even". But the best way is probably to just use a library. Yes, 500MB of additional dependencies, but then it's a one-line…
Re: 4 billion if statements (2023)
#73I prefer data-driven programming, so a simple: return odd_or_evenness[n]; works for me, alongside a pretty big array.
Re: 4 billion if statements (2023)
#74I prefer data-driven programming, so a simple: return odd_or_evenness[n]; works for me, alongside a pretty big array.
const odd_or_evenness = comptime blk: {
var buf: [16]bool = undefined;
var is_even = false;
for (&buf) |*b| {
b.* = is_even;
is_even = !is_even;
}
break :blk buf;
};
This looks like a promising strategy.Re: 4 billion if statements (2023)
#75Re: 4 billion if statements (2023)
#76Earlier quoted context omitted.
>Think deeply about it and tell me if it is not or or not even I think I just experienced a segfault
Why do they call it even when you of in the true number of out false odd the number?
Re: 4 billion if statements (2023)
#77> Now, this is a time-memory tradeoff, but my time on this earth is limited so I decided to meta-program the if statements using a programmer program in a different programming language. for i in range(2*8): if i % 2 == 0: No comment...
Yeah... I come here to talk about that. Should have been for i in range(0, 2**8, 2): print(" if (number == "+str(i)+")") print(" printf(\"even\\n\");") print(" if (number == "+str(i + 1)+")") print(" printf(\"odd\\n\");") or for i in range(0, 2**8, 2): print(f""" if (number == {i}) puts("even"); if (number == {i + 1}) puts("odd");""")
Re: 4 billion if statements (2023)
#78I would also like to praise the visionary genius Ross van der Gussom, without whom this wonderful achievement in software engineering would not have been possible!
Re: 4 billion if statements (2023)
#79> I decided to implement this in the C programming language as it’s by far the fastest language on the planet to this day (thanks to the visionary genius Dennis Richie) Am I lost? Aren't the compiler/linker responsible for fast code, not the language itself?
Most of the difference in speed is the optimizer/linker. Assuming a fair competition the difference between Ada, C, C++, D, Fortran, Rust, Zig (and many others I can't think of) is very rarely even 1% in any real world situation. Of course it isn't hard add pessimization to make any language lose, sometimes accidentally, so fair competitions are very hard to find/make.
Then again, the article was clearly sarcastic.
Re: 4 billion if statements (2023)
#80kind of expected gcc to see right through the 300 gigs of code and compile it down to the tenish instructions.
They disabled optimisations: > Lets compile the code, disabling optimizations with /Od to make sure that the pesky compiler doesn’t interfere with our algorithm