Ok, let's build a foundation here:
A common way of testing primality, is dividing by all primes smaller than the number's square root. For instance, $97$ is prime because dividing by none of the following: {$2,3,5,7$} gives a remainder of $0$. In fact, we can test for primality using the same set of four numbers as long as the number we're testing is between $49$ and $121$.
So let's use that knowledge to look for the largest possible gap in primes between $49$ and $121$. When $49$ is divided by the numbers: {$2,3,5,7$}, you get remainders of {$1,1,4,0$}. $50$ would be {$0,2,0,1$}, adding one to each. When we get to $259$, we're back to {$1,1,4,0$}. Question is, what is the largest gap between numbers where that set doesn't contain a $0$? Using Mathematica we can brute force test with the following code:
consecutiveValues[l_List] := Length /@ Split[l];
plist=Table[Prime[n],{n,1,4}];
mp=Apply[Times,plist];
mdna=Outer[Mod,{m },plist];
tptest=Table[MemberQ[{mdna},0,Infinity],{m,49,mp+49}];
AbsoluteTiming[(Max[consecutiveValues[tptest]]+1)]
Which gives:
{0.000076,10}
So $10$ composites between each prime. Easy enough. Problem is, this gets exponentially more memory intensive as $n$ increases.
Well, now that you get the idea in relation to primes, here's what I'm doing for twin primes:
consecutiveValues[l_List] := Length /@ Split[l]; (*# of consecutive false*)
plist=Table[Prime[n],{n,3,8}];
mp=Apply[Times,plist];
mdna=Outer[Mod,{6m-3 },plist];
tptest=Table[{MemberQ[{mdna},2,Infinity]||MemberQ[{mdna},4,Infinity]},{m,5,5+Ceiling[mp/6]}];
AbsoluteTiming[(Max[consecutiveValues[tptest]]+1)*6]
Using this yields:
{0.086062,150}
This means that in the range {$19^2$ to $23^2$}, a range of 168, there can only be a max gap between twin primes of 150. We can thus guarantee that there is at least 1 twin prime pair in this range.
This code takes advantage of the fact that a number is 4 and 2 more than the two primes of a twin prime pair if its list of remainders contains no 2's or 4's. Otherwise, a number 2 or 4 below it is composite. I've tweaked the code slightly for speed and efficiency (using my very basic knowledge), and have already asked this on Math SE searching for something mathematically I could do differently.
My question is:
What can I do as far as code tweaks that would find twin prime gaps within reasonable memory limits? Right now, Wolfram Programming Lab exits when I use anything above {n,1,9}.