Skip to main content
Tweeted twitter.com/#!/StackMma/status/313646811019620353
More descriptive title
Source Link
István Zachar
  • 47.2k
  • 20
  • 147
  • 307

Making Mathematica more lazy Iterate until condition is met

I want to find the first 5 prime numbers of the form n^6 + 1091$n^6 + 1091$. I have used this code:

 Timing[Select[Table[n^6 + 1091, {n, 10000}], PrimeQ, 5]] 

Which gives the desired answer, and takes 0.0156 seconds. What if I didn't have a rough idea of what values of n$n$ to check?

Timing[Select[Table[n^6 + 1091, {n, 100000}], PrimeQ, 5]] 

Takes 10 times as long.

So, my question is: Is there a simple(ish) way to make MathematicaMathematica stop when the desired number of solutions are found?

Making Mathematica more lazy

I want to find the first 5 prime numbers of the form n^6 + 1091. I have used this code:

 Timing[Select[Table[n^6 + 1091, {n, 10000}], PrimeQ, 5]] 

Which gives the desired answer, and takes 0.0156 seconds. What if I didn't have a rough idea of what values of n to check?

Timing[Select[Table[n^6 + 1091, {n, 100000}], PrimeQ, 5]] 

Takes 10 times as long.

So, my question is: Is there a simple(ish) way to make Mathematica stop when the desired number of solutions are found?

Iterate until condition is met

I want to find the first 5 prime numbers of the form $n^6 + 1091$. I have used this code:

 Timing[Select[Table[n^6 + 1091, {n, 10000}], PrimeQ, 5]] 

Which gives the desired answer, and takes 0.0156 seconds. What if I didn't have a rough idea of what values of $n$ to check?

Timing[Select[Table[n^6 + 1091, {n, 100000}], PrimeQ, 5]] 

Takes 10 times as long.

So, my question is: Is there a simple(ish) way to make Mathematica stop when the desired number of solutions are found?

Source Link
nickjamesuk
  • 883
  • 6
  • 13

Making Mathematica more lazy

I want to find the first 5 prime numbers of the form n^6 + 1091. I have used this code:

 Timing[Select[Table[n^6 + 1091, {n, 10000}], PrimeQ, 5]] 

Which gives the desired answer, and takes 0.0156 seconds. What if I didn't have a rough idea of what values of n to check?

Timing[Select[Table[n^6 + 1091, {n, 100000}], PrimeQ, 5]] 

Takes 10 times as long.

So, my question is: Is there a simple(ish) way to make Mathematica stop when the desired number of solutions are found?