Live data from Hacker News

4 billion if statements (2023)

andreasjhkarlsson.github.io

41–50 of 183 posts

Re: 4 billion if statements (2023)

#41
post #8

Gemini took 4 seconds to answer this prompt: "Here is a number 4200020010101. Think deeply about it and tell me if it is not or or not even." So if you're concerned with privacy issues, you can run the assembly version proposed in the article locally and be well within the same order of performance. Let's thank the author of the article for providing a decent alternative to Google. ah, but the license is not that goo…

>Think deeply about it and tell me if it is not or or not even

I think I just experienced a segfault

Re: 4 billion if statements (2023)

#46

Ah, yes, exactly the pointless diversion I needed for my lunch break. For science: generating a C# switch statement for similar purposes took 7 minutes on similar-ish hardware, but the resulting 99.2GB file could not be opened or compiled ('Stream is too long'), which was slightly disappointing. Optimization efforts included increasing the internal buffer size of the StreamWriter used to create the source code: this…

Isn't the obvious thing to generate different classes for different ranges over the input? Then the classes could be loaded lazily.

And if you then make the ranges tree-shaped you get logarithmic complexity, which massively cuts down the O(n) of the rather naive chained `if` statements.

Re: 4 billion if statements (2023)

#47

I have never seen anyone argue for a ‘switch’ version. switch (v) { case: 0,2,4,8,…: return EVEN; case: 1,3,5,7,…: return ODD; default: return IDK; } Slightly less code to generate.

you forgot the logic to strip the final digit and assign it to v.

processing the whole number is absurd

Re: 4 billion if statements (2023)

#48
post #41
post #8

Gemini took 4 seconds to answer this prompt: "Here is a number 4200020010101. Think deeply about it and tell me if it is not or or not even." So if you're concerned with privacy issues, you can run the assembly version proposed in the article locally and be well within the same order of performance. Let's thank the author of the article for providing a decent alternative to Google. ah, but the license is not that goo…

>Think deeply about it and tell me if it is not or or not even I think I just experienced a segfault

+1

Re: 4 billion if statements (2023)

#49

Ah, yes, exactly the pointless diversion I needed for my lunch break. For science: generating a C# switch statement for similar purposes took 7 minutes on similar-ish hardware, but the resulting 99.2GB file could not be opened or compiled ('Stream is too long'), which was slightly disappointing. Optimization efforts included increasing the internal buffer size of the StreamWriter used to create the source code: this…

I wonder if you could generate it via a Roslyn incremental source generator instead of as a file to bypass this limit. I'm guessing not, but it does sound like fun.
Post reply on HN