I want to know how I find, calculate (make a list in Mathematica) for the firts 50 twin primes. If p is a prime and p+2 is a prime they called twin primes. Anybody who can tell me to programing the program Wolfram Mathematica?
I have come this far, so long:
1) I make a new empty list, that I'm calling "twins"
twins = {}
{}
2) I know that the first twins is 3, 5 and put the element to the list:
AppendTo[twins, {3, 5}]
{{3, 5}}
twins
{{3, 5}}
Ok!
3) I'm checking if the next prime 3+2=5 have a twin and use my conditions:
n = 5
5
If[PrimeQ[n] && PrimeQ[n + 2], AppendTo[twins, {n, n + 2}]]
{{3, 5}, {5, 7}}
Ok!
4) Then I'm checking the lengt of my list:
Length[twins]
2
I's ok!
4) It's ok, but the last thing I want to tell Mathematica is to use the comand "While" and do this:
As long as "twins" has less than 50 elements:
Test if both n and n+2 are primes.
If it is so: put {n,n+2} to the list "twins", then increse
n whith 2 and then return the list "twins".
If you can help you can also send me a Mathematica-file whith the solution (nb-file). to anders.skoog@vaxjofria.se or anders.k.m.skoog@home.se , or just write it down here at the forum. Thanks.
Sorry for those gaps, I copied it straight out of Excel.. Here are the top 35 twin primes: Twin prime - Wikipedia, the free encyclopedia
Hey! Why don't you use the Help in Mathematica?? If you had typed "twin prime" in the search you would have probably found the command you need:
And if you want the first 50 twin primes then choose a big enough number instead of 1000 for example 100000 and modify a little bit in the Select command to display only the first 50 numbers:Code:Select[Range[1000], PrimeQ[#] && NextPrime[#] == 2 + # &]
Code:Select[Range[100000], PrimeQ[#] && NextPrime[#] == 2 + # &, 50]
I am not familiar with Mathematica. I am not sure if what I did in Excel could help you out, but you could do an if/then/while/for (whatever) loop starting at n=2, going from i=2 to i=n-1, and compare n/i - integer(n/i) and use that to see if any numbers are prime. They will be prime if none of those calculations come up as an integer. Then you can do another loop looking at a prime and the number two ahead of it.