Goldbach's comet: Difference between revisions

added RPL
(Added SmileBASIC - added a section for BASIC - currently contains FreeBASIC and SmileBASIC)
(added RPL)
 
(22 intermediate revisions by 12 users not shown)
Line 28:
 
 
 
=={{header|11l}}==
{{trans|Python}}
 
<syntaxhighlight lang="11l">
F is_prime(a)
I a == 2
R 1B
I a < 2 | a % 2 == 0
R 0B
L(i) (3 .. Int(sqrt(a))).step(2)
I a % i == 0
R 0B
R 1B
 
F g(n)
assert(n > 2 & n % 2 == 0, ‘n in goldbach function g(n) must be even’)
V count = 0
L(i) 1 .. n I/ 2
I is_prime(i) & is_prime(n - i)
count++
R count
 
print(‘The first 100 G numbers are:’)
 
V col = 1
L(n) (4.<204).step(2)
print(String(g(n)).ljust(4), end' I (col % 10 == 0) {"\n"} E ‘’)
col++
 
print("\nThe value of G(1000000) is "g(1'000'000))
</syntaxhighlight>
 
{{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|ALGOL 68}}==
Line 445 ⟶ 494:
 
=={{Header|BASIC}}==
==={{header|BASIC256}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">#arraybase 1
print "The first 100 G numbers are:"
 
col = 1
for n = 4 to 202 step 2
print rjust(string(g(n)), 4);
if col mod 10 = 0 then print
col += 1
next n
 
print : print "G(1000000) = "; g(1000000)
end
 
function isPrime(v)
if v <= 1 then return False
for i = 2 to int(sqrt(v))
if v mod i = 0 then return False
next i
return True
end function
 
function g(n)
cont = 0
if n mod 2 = 0 then
for i = 2 to (1/2) * n
if isPrime(i) = 1 and isPrime(n - i) = 1 then cont += 1
next i
end if
return cont
end function</syntaxhighlight>
{{out}}
<pre>Similar to FreeBASIC entry.</pre>
 
==={{header|FreeBASIC}}===
<syntaxhighlight lang="freebasic">Function isPrime(Byval ValorEval As Uinteger) As Boolean
Line 489 ⟶ 573:
 
The value of G(1000000) is 5402</pre>
 
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Use "isprime.bas"
 
Public Sub Main()
Print "The first 100 G numbers are:"
Dim n As Integer, col As Integer = 1
For n = 4 To 202 Step 2
Print Format$(Str(g(n)), "####");
If col Mod 10 = 0 Then Print
col += 1
Next
Print "\nG(1.000.000) = "; g(1000000)
End
 
Function g(n As Integer) As Integer
 
Dim i As Integer, count As Integer = 0
If n Mod 2 = 0 Then
For i = 2 To n \ 2 '(1/2) * n
If isPrime(i) And isPrime(n - i) Then count += 1
Next
End If
Return count
 
End Function</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
==={{Header|SmileBASIC}}===
(click the image to view full-size)
[[File:GoldbachsComet SmileBASIC 3DS screenshot.png|thumb]]
<syntaxhighlight lang="smilebasic">OPTION STRICT: OPTION DEFINT
VAR MAX_G = 4000, MAX_P = 1000000
Line 538 ⟶ 657:
NEXT
NEXT</syntaxhighlight>
 
==={{header|uBasic/4tH}}===
{{trans|FreeBASIC}}
For performance reasons only '''g(100000)''' is calculated. The value "810" has been verified and is correct.
<syntaxhighlight lang="text">Print "The first 100 G numbers are:"
c = 1
 
For n = 4 To 202 Step 2
Print Using "___#"; FUNC(_g(n));
If (c % 10) = 0 Then Print
c = c + 1
Next
 
Print "\nThe value of G(100000) is "; FUNC(_g(100000))
 
End
 
_isPrime
Param (1)
Local (1)
If a@ < 2 Then Return (0)
For b@ = 2 To FUNC(_Sqrt(a@))
If (a@ % b@) = 0 Then Unloop: Return (0)
Next
Return (1)
_g
Param (1)
Local (2)
c@ = 0
If (a@ % 2) = 0 Then 'n in goldbach function g(n) must be even
For b@ = 2 To a@/2
If FUNC(_isPrime(b@)) * FUNC(_isPrime(a@ - b@)) Then c@ = c@ + 1
Next
EndIf
Return (c@)
 
_Sqrt
Param (1)
Local (3)
 
Let b@ = 1
Let c@ = 0
 
Do Until b@ > a@
Let b@ = b@ * 4
Loop
 
Do While b@ > 1
Let b@ = b@ / 4
Let d@ = a@ - c@ - b@
Let c@ = c@ / 2
If d@ > -1 Then
Let a@ = d@
Let c@ = c@ + b@
Endif
Loop
 
Return (c@)</syntaxhighlight>
{{out}}
<pre>The first 100 G numbers are:
Screenshot of the 3DS output from the program (click the image to view full-size):
1 1 1 2 1 2 2 2 2 3
[[File:GoldbachsComet SmileBASIC 3DS screenshot.png|thumb]]
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(100000) is 810
 
0 OK, 0:210 </pre>
 
==={{header|Yabasic}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vb">import isprime
 
print "The first 100 G numbers are:"
 
col = 1
for n = 4 to 202 step 2
print g(n) using ("####");
if mod(col, 10) = 0 print
col = col + 1
next n
 
print "\nG(1000000) = ", g(1000000)
end
 
sub g(n)
count = 0
if mod(n, 2) = 0 then
for i = 2 to (1/2) * n
if isPrime(i) and isPrime(n - i) count = count + 1
next i
fi
return count
end sub</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{Header|C++}}==
<syntaxhighlight lang="c++">
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <stdexcept>
#include <vector>
 
std::vector<bool> primes;
 
void initialise_primes(const int32_t& limit) {
primes.resize(limit);
for ( int32_t i = 2; i < limit; ++i ) {
primes[i] = true;
}
 
for ( int32_t n = 2; n < sqrt(limit); ++n ) {
for ( int32_t k = n * n; k < limit; k += n ) {
primes[k] = false;
}
}
}
 
int32_t goldbach_function(const int32_t& number) {
if ( number <= 2 || number % 2 == 1 ) {
throw std::invalid_argument("Argument must be even and greater than 2: " + std::to_string(number));
}
 
int32_t result = 0;
for ( int32_t i = 1; i <= number / 2; ++i ) {
if ( primes[i] && primes[number - i] ) {
result++;
}
}
return result;
}
 
int main() {
initialise_primes(2'000'000);
 
std::cout << "The first 100 Goldbach numbers:" << std::endl;
for ( int32_t n = 2; n < 102; ++n ) {
std::cout << std::setw(3) << goldbach_function(2 * n) << ( n % 10 == 1 ? "\n" : "" );
}
 
std::cout << "\n" << "The 1,000,000th Goldbach number = " << goldbach_function(1'000'000) << std::endl;
}
</syntaxhighlight>
{{ out }}
<pre>
The first 100 Goldbach numbers:
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 1,000,000th Goldbach number = 5402
</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
function GetGoldbachCount(N: integer): integer;
{Count number of prime number combinations add up to N }
var I: integer;
begin
Result:=0;
{Look at all number pairs that add up to N}
{And see if they are prime}
for I:=1 to N div 2 do
if IsPrime(I) and IsPrime(N-I) then Inc(Result);
end;
 
procedure ShowGoldbachComet(Memo: TMemo);
{Show first 100 Goldback numbers}
var I,N,Cnt,C: integer;
var S: string;
begin
Cnt:=0; N:=2; S:='';
while true do
begin
C:=GetGoldbachCount(N);
if C>0 then
begin
Inc(Cnt);
S:=S+Format('%3d',[C]);
if (Cnt mod 10)=0 then S:=S+CRLF;
if Cnt>=100 then break;
end;
Inc(N,2);
end;
Memo.Lines.Add(S);
end;
 
 
 
</syntaxhighlight>
{{out}}
<pre>
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
 
 
Elapsed Time: 1.512 ms.
 
</pre>
 
 
=={{header|EasyLang}}==
{{trans|AWK}}
 
<syntaxhighlight lang="easylang">
func isprim n .
if n mod 2 = 0 and n > 2
return 0
.
i = 3
sq = sqrt n
while i <= sq
if n mod i = 0
return 0
.
i += 2
.
return 1
.
func goldbach n .
for i = 2 to n div 2
if isprim i = 1
cnt += isprim (n - i)
.
.
return cnt
.
numfmt 0 3
for n = 4 step 2 to 202
write goldbach n
if n mod 20 = 2
print ""
.
.
print goldbach 1000000
</syntaxhighlight>
 
=={{header|J}}==
Line 578 ⟶ 963:
 
Instead, for G(1e6), we find all primes less than a million, subtract each from 1 million and count how many of the differences are prime and cut that in half. We cut that sum in half because this approach counts each pair twice (once with the smallest value first, again with the smallest value second -- since 1e6 is not the square of a prime we do not have a prime which appears twice in one of these sums).
 
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
 
import javax.imageio.ImageIO;
 
public final class GoldbachsComet {
 
public static void main(String[] aArgs) {
initialisePrimes(2_000_000);
System.out.println("The first 100 Goldbach numbers:");
for ( int n = 2; n < 102; n++ ) {
System.out.print(String.format("%3d%s", goldbachFunction(2 * n), ( n % 10 == 1 ? "\n" : "" )));
}
System.out.println();
System.out.println("The 1,000,000th Goldbach number = " + goldbachFunction(1_000_000));
createImage();
}
private static void createImage() {
final int width = 1040;
final int height = 860;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, width, height);
List<Color> colours = List.of( Color.BLUE, Color.GREEN, Color.RED );
for ( int n = 2; n < 2002; n++ ) {
graphics.setColor(colours.get(n % 3));
graphics.fillOval(n / 2, height - 5 * goldbachFunction(2 * n), 10, 10);
}
try {
ImageIO.write(image, "png", new File("GoldbachsCometJava.png"));
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
private static int goldbachFunction(int aNumber) {
if ( aNumber <= 2 || aNumber % 2 == 1 ) {
throw new AssertionError("Argument must be even and greater than 2: " + aNumber);
}
int result = 0;
for ( int i = 1; i <= aNumber / 2; i++ ) {
if ( primes[i] && primes[aNumber - i] ) {
result += 1;
}
}
return result;
}
private static void initialisePrimes(int aLimit) {
primes = new boolean[aLimit];
for ( int i = 2; i < aLimit; i++ ) {
primes[i] = true;
}
for ( int n = 2; n < Math.sqrt(aLimit); n++ ) {
for ( int k = n * n; k < aLimit; k += n ) {
primes[k] = false;
}
}
}
private static boolean[] primes;
 
}
</syntaxhighlight>
{{ out }}
[[Media:GoldbachsCometJava.png]]
<pre>
The first 100 Goldbach numbers:
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 1,000,000th Goldbach number = 5402
</pre>
 
=={{header|jq}}==
'''Works with jq and gojq, the C and Go implementations of jq.'''
 
'''Preliminaries'''
<syntaxhighlight lang=jq>
def count(s): reduce s as $_ (0; .+1);
 
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
 
def nwise($n):
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
n;
 
def is_prime:
. as $n
| if ($n < 2) then false
elif ($n % 2 == 0) then $n == 2
elif ($n % 3 == 0) then $n == 3
elif ($n % 5 == 0) then $n == 5
elif ($n % 7 == 0) then $n == 7
elif ($n % 11 == 0) then $n == 11
elif ($n % 13 == 0) then $n == 13
elif ($n % 17 == 0) then $n == 17
elif ($n % 19 == 0) then $n == 19
else
($n | sqrt) as $rt
| 23
| until( . > $rt or ($n % . == 0); .+2)
| . > $rt
end;
</syntaxhighlight>
'''The Tasks'''
<syntaxhighlight lang=jq>
# emit nothing if . is odd
def G:
select(. % 2 == 0)
| count( range(2; (./2)+1) as $i
| select(($i|is_prime) and ((.-$i)|is_prime)) );
 
def task1:
"The first 100 G numbers:",
([range(4; 203; 2) | G] | nwise(10) | map(lpad(4)) | join(" "));
 
def task($n):
$n, 4, 22
|"G(\(.)): \(G)";
 
task1, "", task(1000000)
</syntaxhighlight>
{{output}}
<pre>
The first 100 G numbers:
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
 
G(1000000): 5402
G(4): 1
G(22): 3
</pre>
 
=={{header|Julia}}==
Run in VS Code or REPL to view and save the plot.
<syntaxhighlight lang="rubyjulia">using Combinatorics
using Plots
using Primes
Line 611 ⟶ 1,161:
The value of G(1000000) is 5402
</pre>
[[File:Jgoldbachplot.png]]
 
=={{header|Lua}}==
Line 655 ⟶ 1,206:
8 13 5 8 11 7 9 13 8 9
G(1000000) = 5402</pre>
 
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Line 681 ⟶ 1,233:
[graphical object showing Goldbach's comet]</pre>
 
=={{header|Nim}}==
{{libheader|nim-plotly}}
{{libheader|chroma}}
To display the Golbach’s comet, we use a library providing a Nim interface to “plotly”. The graph is displayed into a browser.
<syntaxhighlight lang="Nim">import std/[math, strformat, strutils, sugar]
import chroma, plotly
 
const
N1 = 100 # For part 1 of task.
N2 = 1_000_000 # For part 2 of task.
N3 = 2000 # For stretch part.
 
# Erathostenes sieve.
var isPrime: array[1..N1, bool]
for i in 2..N1: isPrime[i] = true
for n in 2..sqrt(N1.toFloat).int:
for k in countup(n * n, N1, n):
isPrime[k] = false
 
proc g(n: int): int =
## Goldbach function.
assert n > 2 and n mod 2 == 0, "“n” must be even and greater than 2."
for i in 1..(n div 2):
if isPrime[i] and isPrime[n - i]:
inc result
 
# Part 1.
echo &"First {N1} G numbers:"
var col = 1
for n in 2..N1:
stdout.write align($g( 2 * n), 3)
stdout.write if col mod 10 == 0: '\n' else: ' '
inc col
 
# Part 2.
echo &"\nG({N2}) = ", g(N2)
 
# Stretch part.
 
const Colors = collect(for name in ["red", "blue", "green"]: name.parseHtmlName())
var x, y: seq[float]
var colors: seq[Color]
for n in 2..N3:
x.add n.toFloat
y.add g(2 * n).toFloat
colors.add Colors[n mod 3]
 
let trace = Trace[float](type: Scatter, mode: Markers, marker: Marker[float](color: colors), xs: x, ys: y)
let layout = Layout(title: "Goldbach’s comet", width: 1200, height: 400)
Plot[float64](layout: layout, traces: @[trace]).show(removeTempFile = true)
</syntaxhighlight>
{{out}}
<pre>First 100 G numbers:
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
 
G(1000000) = 5402
</pre>
 
=={{header|Perl}}==
Line 877 ⟶ 1,495:
The value of G(1000000) is 5402
</pre>
[[File:PGoldbachplot.png]]
 
=={{header|Raku}}==
Line 920 ⟶ 1,539:
 
'''Stretch goal:''' (offsite SVG image) [https://raw.githubusercontent.com/thundergnat/rc/master/img/Goldbachs-Comet-Raku.svg Goldbachs-Comet-Raku.svg]
 
=={{header|RPL}}==
{{works with|HP|49}}
« '''IF''' 2 MOD '''THEN'''
"GOLDB Error: Odd number" DOERR
'''ELSE'''
0
2 PICK3 2 / CEIL '''FOR''' j
'''IF''' j ISPRIME? '''THEN'''
'''IF''' OVER j - ISPRIME? '''THEN''' 1 + '''END'''
'''END'''
'''NEXT''' NIP
'''END'''
» '<span style="color:blue">GOLDB</span>' STO
« « n <span style="color:blue">GOLDB</span> » 'n' 4 202 2 SEQ
OBJ→ DROP { 10 10 } →ARRY
1000000 <span style="color:blue">GOLDB</span> "G(1000000)" →TAG
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
2: [[ 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 ]]
1: G(1000000): 5402
</pre>
 
=={{header|Ruby}}==
following the J comments, but only generating primes up-to half a million
<syntaxhighlight lang="ruby">require 'prime'
 
n = 100
puts "The first #{n} Godbach numbers are: "
sums = Prime.each(n*2 + 2).to_a[1..].repeated_combination(2).map(&:sum)
sums << 4
sums.sort.tally.values[...n].each_slice(10){|slice| puts "%4d"*slice.size % slice}
 
n = 1000000
puts "\nThe value of G(#{n}) is #{Prime.each(n/2).count{|pr| (n-pr).prime?} }."
</syntaxhighlight>
{{out}}
<pre>The first 100 Godbach 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|Rust}}==
Line 999 ⟶ 1,680:
 
{{out}}
Writes a file in SVG format to the current directory with similar content to the Raku example.
<pre>
First 100 G numbers:
Line 1,016 ⟶ 1,696:
</pre>
 
[[Media:Goldbach's comet rust.svg]]
=={{header|uBasic/4tH}}==
{{trans|FreeBASIC}}
For performance reasons only '''g(100000)''' is calculated. The value "810" has been verified and is correct.
<syntaxhighlight lang="text">Print "The first 100 G numbers are:"
c = 1
 
For n = 4 To 202 Step 2
Print Using "___#"; FUNC(_g(n));
If (c % 10) = 0 Then Print
c = c + 1
Next
 
Print "\nThe value of G(100000) is "; FUNC(_g(100000))
 
End
 
_isPrime
Param (1)
Local (1)
If a@ < 2 Then Return (0)
For b@ = 2 To FUNC(_Sqrt(a@))
If (a@ % b@) = 0 Then Unloop: Return (0)
Next
Return (1)
_g
Param (1)
Local (2)
c@ = 0
If (a@ % 2) = 0 Then 'n in goldbach function g(n) must be even
For b@ = 2 To a@/2
If FUNC(_isPrime(b@)) * FUNC(_isPrime(a@ - b@)) Then c@ = c@ + 1
Next
EndIf
Return (c@)
 
_Sqrt
Param (1)
Local (3)
 
Let b@ = 1
Let c@ = 0
 
Do Until b@ > a@
Let b@ = b@ * 4
Loop
 
Do While b@ > 1
Let b@ = b@ / 4
Let d@ = a@ - c@ - b@
Let c@ = c@ / 2
If d@ > -1 Then
Let a@ = d@
Let c@ = c@ + b@
Endif
Loop
 
Return (c@)</syntaxhighlight>
{{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(100000) is 810
 
0 OK, 0:210 </pre>
 
=={{header|Wren}}==
{{libheader|DOME}}
{{libheader|Wren-math}}
{{libheader|Wren-traititerate}}
{{libheader|Wren-fmt}}
{{libheader|Wren-plot}}
This follows the Raku example in plotting the first two thousand G values rather than the values up to G(2000) in order to produce an image something like the image in the Wikipedia article.
<syntaxhighlight lang="ecmascriptwren">import "dome" for Window
import "graphics" for Canvas, Color
import "./math2" for Int
import "./traititerate" for Stepped
import "./fmt" for Fmt
import "./plot" for Axes
1,150

edits