4 billion if statements (2023)
161–170 of 183 posts
Re: 4 billion if statements (2023)
#162Earlier quoted context omitted.
It's a constant number of lookups, and all good Computer Scientists know that it is therefore an O(1) algorithm. It is hard to imagine better efficiency than O(1)! Indeed we could improve it further by performing all evaluations even when we find the answer earlier, ensuring it is a true Constant Time algorithm, safe for use in cryptography.
> This is time efficient* but rather wasteful of space. You're saying that the blog's solution is time efficient. Which it is not. Your solution may be O(1) but it is also not efficient. As I'm sure you are aware. I can tell you a practical solution which is also O(1) and takes up maybe 2 or 3 instructions of program code and no extra memory at all. `x & 1` or `x % 2 != 0` This blog post was taking a joke and running…
We already know. Everybody knows. That's the joke. There's no need to point out anything.
Re: 4 billion if statements (2023)
#163Re: 4 billion if statements (2023)
#164Lol
Re: 4 billion if statements (2023)
#165I know it's silly, but I just want to fix his first version with the minimum possible changes; /* Copyright 2023. All unauthorized distribution of this source code will be persecuted to the fullest extent of the law*/ #include #include #include int main(int argc, char* argv[]) { uint8_t number = argc>1 ? argv[1][strlen(argv[1])-1]-'0' : printf("Usage: odd-or-even number\n"); if (number == 0) printf("even\n"); if (num…
Or is the performance considered worse because it becomes O(n) (where n < MAX_UINT) vs. constant time ( O(MAX_UINT) )
Re: 4 billion if statements (2023)
#166Re: 4 billion if statements (2023)
#167I know it's silly, but I just want to fix his first version with the minimum possible changes; /* Copyright 2023. All unauthorized distribution of this source code will be persecuted to the fullest extent of the law*/ #include #include #include int main(int argc, char* argv[]) { uint8_t number = argc>1 ? argv[1][strlen(argv[1])-1]-'0' : printf("Usage: odd-or-even number\n"); if (number == 0) printf("even\n"); if (num…
Wouldn't using elif for all comparisons after the first improve performance? Or is the performance considered worse because it becomes O(n) (where n < MAX_UINT) vs. constant time ( O(MAX_UINT) )
Re: 4 billion if statements (2023)
#168God help us if that code ever makes it's way onto npm. isEven is a performant, hand-compiled evenness checker for any 32 bit integer. A single file import that does one job and one job only!
it follows the UNIX philosophy of doing one thing and donig it well.
Re: 4 billion if statements (2023)
#169This is time efficient* but rather wasteful of space. The best way to save space is to use a Bloom Filter. If we capture all the even numbers, that would sadly only give us "Definitely not Even" or "Maybe Even". But for just the cost of doubling our space, we can use two Bloom filters! So we can construct one bloom filter capturing even numbers, and another bloom filter capturing odd numbers. Now we have "Definitely…
https://gist.github.com/alexjurkiewicz/1abf05f16fd98aabf380c...
Re: 4 billion if statements (2023)
#170Earlier quoted context omitted.
Yeeessss! Microservices!
Your mention of Microservices opened up my mind to additional possibilities. How about we create a microservice for each integer, then deploy 4 billion of them. Send a request to all of them simultaneously. Only one of them will respond with the answer. We still need to decide how to deploy those microservices - one per machine, or multiple per machine?