看板 ott
作者 ott (寶貝)
標題 Table the firts 50 twin primes in Mathematica
時間 2013年07月01日 Mon. AM 05:21:35


       
     
   
 




Table the firts 50 twin primes in Mathematica
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.
Last edited by Bigas; February 2nd 2008 at 01:53 AM.















 
 

--
※ 作者: ott 時間: 2013-07-01 05:21:35
※ 看板: ott 文章推薦值: 0 目前人氣: 0 累積人氣: 99 
分享網址: 複製 已複製
guest
x)推文 r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇