Goldbach's comet: Difference between revisions

Goldbach's comet en FreeBASIC
m (→‎{{header|Phix}}: minor tidy, added requires("1.0.2"), since it does)
(Goldbach's comet en FreeBASIC)
Line 349:
 
Here, you can find the result of the visualization - or the "Goldbach's comet": [https://i.ibb.co/JvLDRc0/Screenshot-2022-05-07-at-11-35-23.png 2D-chart of all G values up to 2000]
 
 
=={{header|FreeBASIC}}==
<lang freebasic>Function isPrime(Byval ValorEval As Uinteger) As Boolean
If ValorEval <= 1 Then Return False
For i As Integer = 2 To Int(Sqr(ValorEval))
If ValorEval Mod i = 0 Then Return False
Next i
Return True
End Function
 
Function g(n As Uinteger) As Uinteger
Dim As Uinteger i, count = 0
If (n Mod 2 = 0) Then 'n in goldbach function g(n) must be even
For i = 2 To (1/2) * n
If isPrime(i) And isPrime(n - i) Then count += 1
Next i
End If
Return count
End Function
 
Print "The first 100 G numbers are:"
 
Dim As Uinteger col = 1
For n As Uinteger = 4 To 202 Step 2
Print Using "####"; g(n);
If (col Mod 10 = 0) Then Print
col += 1
Next n
 
Print !"\nThe value of G(1000000) is "; g(1000000)
Sleep</lang>
{{out}}
<pre>The first 100 G numbers are:
1 1 1 2 1 2 2 2 2 3
3 3 2 3 2 4 4 2 3 4
3 4 5 4 3 5 3 4 6 3
5 6 2 5 6 5 5 7 4 5
8 5 4 9 4 5 7 3 6 8
5 6 8 6 7 10 6 6 12 4
5 10 3 7 9 6 5 8 7 8
11 6 5 12 4 8 11 5 8 10
5 6 13 9 6 11 7 7 14 6
8 13 5 8 11 7 9 13 8 9
 
The value of G(1000000) is 5402</pre>
 
 
=={{header|J}}==
2,122

edits