I think it’s unlikely that is the fastest way to test for primes in java.
It also has the amusing characteristic of crashing if your number is larger than the largest contiguous span of free memory in the JVM heap.
The JVM heap can keep growing as long as the OS allocator never says no.
Virtual memory compression at the OS level should be able to compress strings of char[n] to char[lg(n)] with run-length encoding.
(Well, in theory. I never tried running it :P)
You’ll run into a much tighter, much stupider limit much sooner than that becomes relevant: the longest possible Java array only has 2 billion-ish elements (2^31-1, to be precise, because Java arrays are indexed by Java ints, which are 32 bit and signed). I can comfortably fit the largest possible char array—4GB—uncompressed in memory on every computer I use regularly.
No, it can’t. The JVM has a maximum heap size set at start up, which defaults to 1GB or less. And even if the OS compresses that memory, the JVM allocator still counts the uncompressed size.
Ah ok. I guess -Xmx999999g is in order.
Sounds like the regex compiler has its work cut out.
Naw, this is just for fun :)
No need for the redundant programming tag here.