frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

4 billion if statements (2023)

https://andreasjhkarlsson.github.io//jekyll/update/2023/12/27/4-billion-if-statements.html
71•damethos•5d ago

Comments

thewisenerd•1h ago
discussed 2 years ago,

https://news.ycombinator.com/item?id=38790597

4B If Statements (469 comments)

unwind•1h ago
Meta: Yeah, this should have a "(2023)" tag in the title. Thanks.
SiempreViernes•1h ago
> As a side note, the program is amazingly performant. For small numbers the results are instantaneous and for the large number close to the 2^32 limit the result is still returned in around 10 seconds.

Amazing!

isoprophlex•1h ago
> Visionary genius Ross van der Gussom

Thanks for making me doubt myself & googling who that guy who made python was again, because surely "van der Gussom" isn't a normal Dutch name. Well played.

d-lisp•53m ago
if(n&1)

else

imtringued•27m ago
You can do it even faster with the if statements:

    #include <stdio.h>
    #include <stdlib.h>

    int main(int argc, char *argv[])
    {
        if (argc < 2) {
            fprintf(stderr, "Usage: %s <string>\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\n");
        if (d == '1')
            printf("odd\n");
        if (d == '2')
            printf("even\n");
        if (d == '3')
            printf("odd\n");
        if (d == '4')
            printf("even\n");
        if (d == '5')
            printf("odd\n");
        if (d == '6')
            printf("even\n");
        if (d == '7')
            printf("odd\n");
        if (d == '8')
            printf("even\n");
        if (d == '9')
            printf("odd\n");
    
        return 0;
    }

gcc -std=c11 -Wall -Wextra -O2 -o check_digit check_digit.c

./check_digit 999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

Tistron•11m ago
You can do it even even faster by replacing your if statements (works because the ascii values end in the digit they represent):

    if (d & 1)
       printf("odd\n");
    else 
       printf("even\n")
wiz21c•9m ago
I'm disappointed, it's not in rust. :-)
tetris11•4m ago
probably easier in bash:

    number="$1"
    if [[ "$number" =~ "^(2|4|6|8|10|12|14|16|18|20)$" ]]; then
        echo even
    elif [[ "$number" =~ "^(1|3|5|7|9|11|13|15|17|19)$" ]]; then
        echo odd
    else
        echo Nan
    fi
A bit limited, but you can scale it up
tigranbs•44m ago
This reminds me of my personal "prime number" grabber research https://github.com/tigranbs/prime-numbers I needed to create the unique graph nodes and assign prime numbers, and to make things efficient, I thought, why not just download the list of known prime numbers instead of generating them one by one. So I did and compiled everything with a single Go binary. Ehh, good old days with a nice feith in making "the best" crappy software out there.
wiz21c•40m ago
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 good we can't reproduce his code.

orzig•34m ago
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)
xg15•33m ago
> 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...
cowsandmilk•30m ago
How horridly inefficient, he should have just flipped a Boolean on each iteration.
kroolik•22m ago
Horridly inefficient. Just unfold the loop.
_ache_•29m ago
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");""")
wvbdmp•31m ago
Next put them in a tree for faster lookups.
wiz21c•12m ago
With a tree you'll be limited by the RAM. I advise to use a database.
d--b•5m ago
Don't reinvent the wheel, put them in a SQLite table, and let the sql engine create the tree for you!
ZeroConcerns•24m ago
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 reduced the runtime to around 6 minutes, as well as running a non-debug build, as it was observed that the poor Visual Studio metrics gathering process was contributing significantly to disk activity as well, but that ultimately didn't matter much. So, ehhm, yes, good job on that I guess?

whynotmaybe•16m ago
> 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?

croes•12m ago
People often use language as synonym for the whole ecosystem including compiler and linker
reedf1•7m ago
It's a wild statement for a few reasons; your observation is one of them.
mbivert•2m ago
> I decided to use the slowest language on the planet, Python (thanks to the visionary genius of Ross van der Gussom).

given the article, it's fair to assume the author was joking around

that being said, the way the language is used and its ecosystem do contribute to the executable's efficiency. yet, given C's frugality, or the proximity between its instructions and the executed ones, it's not unfair to say that "C is fast"

KeplerBoy•12m ago
kind of expected gcc to see right through the 300 gigs of code and compile it down to the tenish instructions.
philippta•6m ago
> 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.

ricardo81•1m ago
Presumably after the first run much or all of the program is paged into OS memory

The tiniest yet real telescope I've built

https://lucassifoni.info/blog/miniscope-tiny-telescope/
133•chantepierre•4h ago•23 comments

4 billion if statements (2023)

https://andreasjhkarlsson.github.io//jekyll/update/2023/12/27/4-billion-if-statements.html
71•damethos•5d ago•27 comments

After 27 years within budget Austria open 6thlongest railway tunnel in the world

https://infrastruktur.oebb.at/en/projects-for-austria/railway-lines/southern-line-vienna-villach/...
12•fzeindl•1h ago•0 comments

GPT-5.2

https://openai.com/index/introducing-gpt-5-2/
1024•atgctg•17h ago•879 comments

Nokia N900 Necromancy

https://yaky.dev/2025-12-11-nokia-n900-necromancy/
337•yaky•11h ago•118 comments

Google de-indexed Bear Blog and I don't know why

https://journal.james-zhan.com/google-de-indexed-my-entire-bear-blog-and-i-dont-know-why/
198•nafnlj•10h ago•77 comments

Guarding My Git Forge Against AI Scrapers

https://vulpinecitrus.info/blog/guarding-git-forge-ai-scrapers/
42•todsacerdoti•4h ago•33 comments

CRISPR fungus: Protein-packed, sustainable, and tastes like meat

https://www.isaaa.org/kc/cropbiotechupdate/article/default.asp?ID=21607
173•rguiscard•11h ago•93 comments

Smartphone without a battery (2022)

https://yaky.dev/2022-09-06-smartphone-without-battery/
38•MYEUHD•4h ago•3 comments

Rivian Unveils Custom Silicon, R2 Lidar Roadmap, and Universal Hands Free

https://riviantrackr.com/news/rivian-unveils-custom-silicon-r2-lidar-roadmap-universal-hands-free...
320•doctoboggan•17h ago•424 comments

Octo: A Chip8 IDE

https://github.com/JohnEarnest/Octo
8•tosh•6d ago•1 comments

The highest quality codebase

https://gricha.dev/blog/the-highest-quality-codebase
562•Gricha•3d ago•358 comments

Programmers and software developers lost the plot on naming their tools

https://larr.net/p/namings.html
315•todsacerdoti•17h ago•408 comments

Spirograph style Lego drawing machine

https://jkbrickworks.com/simple-drawing-machine/
15•ensocode•4d ago•2 comments

He set out to walk around the world. After 27 years, his quest is nearly over

https://www.washingtonpost.com/lifestyle/2025/12/05/karl-bushby-walk-around-world/
133•wallflower•4d ago•81 comments

An SVG is all you need

https://jon.recoil.org/blog/2025/12/an-svg-is-all-you-need.html
261•sadiq•16h ago•106 comments

Litestream VFS

https://fly.io/blog/litestream-vfs/
312•emschwartz•18h ago•78 comments

Denial of service and source code exposure in React Server Components

https://react.dev/blog/2025/12/11/denial-of-service-and-source-code-exposure-in-react-server-comp...
297•sangeeth96•15h ago•182 comments

Stoolap: High-performance embedded SQL database in pure Rust

https://github.com/stoolap/stoolap
83•murat3ok•11h ago•18 comments

Auto-grading decade-old Hacker News discussions with hindsight

https://karpathy.bearblog.dev/auto-grade-hn/
617•__rito__•1d ago•255 comments

Show HN: Sim – Apache-2.0 n8n alternative

https://github.com/simstudioai/sim
207•waleedlatif1•18h ago•46 comments

Craft software that makes people feel something

https://rapha.land/craft-software-that-makes-people-feel-something/
302•lukeio•22h ago•145 comments

The architecture of “not bad”: Decoding the Chinese source code of the void

https://suggger.substack.com/p/the-architecture-of-not-bad-decoding
104•Suggger•21h ago•123 comments

Einstein: NewtonOS running on other operating systems

https://github.com/pguyot/Einstein
69•fanf2•4d ago•7 comments

Laying out the 404 Media zine

https://tedium.co/2025/12/10/404-media-zine-linux-affinity/?
69•robenkleene•11h ago•7 comments

The Walt Disney Company and OpenAI Partner on Sora

https://openai.com/index/disney-sora-agreement/
240•inesranzo•21h ago•465 comments

French supermarket's Christmas advert is worldwide hit (without AI) [video]

https://www.youtube.com/watch?v=Na9VmMNJvsA
389•gbugniot•22h ago•203 comments

Cadmium Zinc Telluride: The wonder material powering a medical 'revolution'

https://www.bbc.com/news/articles/c24l223d9n7o
49•1659447091•10h ago•13 comments

Pdsink: USB Power Delivery Sink library for embedded devices

https://github.com/pdsink/pdsink
44•zdw•5d ago•14 comments

Native ads coming soon to Stack Overflow and Stack Exchange

https://meta.stackexchange.com/questions/415259/native-ads-coming-soon-to-stack-overflow-and-stac...
8•exploraz•1h ago•8 comments