Live data from Hacker News

4 billion if statements (2023)

andreasjhkarlsson.github.io

141–150 of 183 posts

Re: 4 billion if statements (2023)

#141
This reminds me of when I learned to program on my casio calculator.

There was a function to detect a key press which would return a number identifying the pressed key.

I needed to map that number to the letter printed on the key to print it on the screen. I don't remember whether there was no hashmap data structure or I just didn't know about it, but I implemented it with a serie of if.

The problem with that solution is that while mapping A was fast, Z was very slow because it was at the end of the list. That is how I discovered divide and conquer/ dichotomy with if branches.

Re: 4 billion if statements (2023)

#142

I see this is 2023… the article refs GPT even then. Can’t believe it’s already that much time gone by, still seems like “last years big news” I was gonna comment “this is what I really like to see on HN”. Then I saw the date and was sad that we’re having to dip into the history box to find fun/interesting articles more often of late it seems. Anyone else interested in a temporary moratorium on all things LLM? We coul…

> Anyone else interested in a temporary moratorium on all things LLM? We could have GPT-free-Wednesday, or something like that :)

I would be interested in a permanent moratorium, personally. There's no interesting content to be had in the various LLM articles that litter HN these days. Or failing a topic ban, at least give a way to filter it for those of us who are sick of hearing about AI hype.

Re: 4 billion if statements (2023)

#143
post #81
post #54

Earlier quoted context omitted.

I'm curious what GCC would do if it wasn't purposely lobotomised and fed 300 GB of this nuclear waste.

Well I created the 16 bit .c file, because I'm not that curious. gcc -O0 completed immediately and made a 1,5MB executable. -O1 took about 10 minutes for a 1,8 MB executable. -O2 has been running for 1h15m so far... i7-14700K I'm in too deep now, so I'll let it run while I'm at work.

Keep us updated.

Re: 4 billion if statements (2023)

#144
post #92

Earlier quoted context omitted.

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.

You can totally use source generators for that.

You're only allowed up to 65535 locals, but this includes hidden locals, which the compiler adds if you're compiling in debug mode.

So you have to make sure to compile only in release mode just to get to 16 bits.

Re: 4 billion if statements (2023)

#145
post #103

Earlier quoted context omitted.

> But for just the cost of doubling our space, we can use two Bloom filters! We can optimize the hash function to make it more space efficient. Instead of using remainders to locate filter positions, we can use a mersenne prime number mask (like say 31), but in this case I have a feeling the best hash function to use would be to mask with (2^1)-1.

This produced strange results on my ternary computer. I had to use a recursive popcnt instead.

this is my new favorite comment on this cursed website

Re: 4 billion if statements (2023)

#146
i tried in ruby up to 1 million (1 billion was taking too long)

    File.write("check.rb", (["if i == 0\n  puts :even"] + (1..1_000_000).map { |i| "elsif i == #{i}\n  puts :#{i % 2 == 0 ? "even" : "odd"}" } + ["end\n"]).join("\n"))
and added at the top

    i = ARGV.first.to_i
but i'm getting SIGILL

    fish: Job 1, 'ruby check.rb 0' terminated by signal SIGILL (Illegal instruction)

Re: 4 billion if statements (2023)

#147

Earlier quoted context omitted.

Good point. Have two programs - one checking every even number and returning odd of not even. And then have a program checking every odd number and returning even if not. Then, a simple program to dispatch to either program randomly, so you end up in the long term with good performance for each.

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?

Re: 4 billion if statements (2023)

#149

Earlier quoted context omitted.

How is this time efficient at all? It takes upwards of 40 seconds to compute on large 32bit values. It's a joke post with some interesting bits and details.

You're absolutely right. The obvious solution would have been to create a boolean table containing all the pre-computed answers, and then simply use the integer you are testing as the index of the correct answer in memory. Now your isEven code is just a simple array lookup! Such an obvious improvement, I can't believe the OP didn't see it. And with a little extra work you can shrink the whole table's size in memory b…

Maybe we can even find some correlation in the bit pattern of the input and the Boolean table!
Post reply on HN