In the "finder" method, you might be checking multiple times the same number to know if it is a prime number or not.
Example : gap(6, 2, 20), you will check 2 and 8 (x = 2), then 3 and 9 (x = 3), then 4 (x = 4), then 5 and 11 plus 6 and 7 (between 5 and 11 until a prime is found) (x = 5), then 6 (x = 6), then 7 and 13 (x = 7), etc. In that example, 6 and 7 have already been checked twice.
I just want to point out that:
bits.replaceAll("^0+", "").replaceAll("0+$", "");
Can be shortened to: bits.replaceAll("^0+|0+$", "").
The "or" operator is a handy sign~
Nice one :)
As a little improvements :
In the "finder" method, you might be checking multiple times the same number to know if it is a prime number or not.
Example : gap(6, 2, 20), you will check 2 and 8 (x = 2), then 3 and 9 (x = 3), then 4 (x = 4), then 5 and 11 plus 6 and 7 (between 5 and 11 until a prime is found) (x = 5), then 6 (x = 6), then 7 and 13 (x = 7), etc. In that example, 6 and 7 have already been checked twice.