←back to thread

60 points ortusdux | 1 comments | | HN request time: 0s | source
Show context
tholman ◴[] No.42073444[source]
Fun hypothetical, or can someone solve? How long, would this regex prime check [1] (via hn 2009) take to run on this on todays average machine?

Hitchhiker's Guide's Deep Thought "42" was 7.5 million years, just for a guide-post.

- [1] https://news.ycombinator.com/item?id=707236

replies(2): >>42073530 #>>42074574 #
chx ◴[] No.42073530[source]
https://stackoverflow.com/a/17189376/308851 claims it's O(N^2). 10^82 operations ... say you can run 10^10 iterations in a second which no current CPU is capable of but let's pretend, it's not like a factor of 10 or 100 will make a big difference given how this is like 10^54 times the age of universe.

This algorithm is not practical.

replies(2): >>42074074 #>>42074613 #
lifthrasiir ◴[] No.42074613[source]
Here N should be interpreted as the number itself, not the number of digits (in any base). So the actual complexity is exponential in terms of the number of digits and in fact it will take about 10^(10^8) times the age of universe to build the string alone.
replies(1): >>42075833 #
1. chx ◴[] No.42075833{3}[source]
Oh.

It's really not practical.