Live data from Hacker News

4 billion if statements (2023)

andreasjhkarlsson.github.io

31–40 of 183 posts

Re: 4 billion if statements (2023)

#31
post #10

> 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...

I think we can improve this. Just make a microservice who generates the code on the fly and streams it to the compiler. Then you also just have to create the necessary code and don't waste the SSD with unused code-paths.

Re: 4 billion if statements (2023)

#32
post #22

Earlier quoted context omitted.

You can do it even faster with the if statements: #include #include int main(int argc, char *argv[]) { if (argc \n", argv[0]); return 1; } char *s = argv[1]; int i; /* find the end of the string */ for (i = 0; s[i] != '\0'; ++i) ; /* make sure the string wasn't empty */ if (i == 0) { fprintf(stderr, "Error: empty string\n"); return 1; } /* last character is at s[i - 1] */ char d = s[i - 1]; if (d == '0') printf("even…

I'm disappointed, it's not in rust. :-)

Still hoping for the C++ template version. Don’t pay for what you don’t use!

Re: 4 billion if statements (2023)

#35

kind 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

Re: 4 billion if statements (2023)

#37

> I saw from the SSD was around 800 MB/s (which doesn’t really make sense as that should give execution speeds at 40+ seconds, but computers are magical so who knows what is going on). If anyone knows what’s actually going on, please do tell.

I'm not entirely sure but could it be predictive branching?

Re: 4 billion if statements (2023)

#38
post #9

If the author is available for consulting I have this bag of rice I need cooked. Should be around 30,000 grains, each needs about 1mL of water and 2m on the stove. Will pay $10 (2025 dollars)

Aha, you forgot to specify the country of those "dollars"! For $10 (2025 [Cayman Islands] dollars)! Which is higher than USD10

Re: 4 billion if statements (2023)

#39
post #9

If the author is available for consulting I have this bag of rice I need cooked. Should be around 30,000 grains, each needs about 1mL of water and 2m on the stove. Will pay $10 (2025 dollars)

Aha, you forgot to specify the country of those "dollars"! For $10 (2025 [Cayman Islands] dollars)! Which is higher than USD10

Zimbabwe: 0.027 USD

Re: 4 billion if statements (2023)

#40
post #10

> 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...

How horridly inefficient, he should have just flipped a Boolean on each iteration.

Just output odd and even for each pass and increment by two. Need to make sure you have the right starting value, and check for off-by-one errors.
Post reply on HN