Goldbach's comet: Difference between revisions

Content added Content deleted
(Added Algol 68)
Line 28: Line 28:





=={{header|ALGOL 68}}==
Generates an ASCII-Art scatter plot - the vertical axis is n/10 and the hotizontal is G(n).
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # calculate values of the Goldbach function G where G(n) is the number #
# of prime pairs that sum to n, n even and > 2 #
# generates an ASCII scatter plot of G(n) up to G(2000) #
PR read "primes.incl.a68" PR # include prime utilities #
INT max number = 1 000 000; # maximum number we will consider #
# get a list of primes up to max number #
[]INT prime list = EXTRACTPRIMESUPTO max number FROMPRIMESIEVE PRIMESIEVE max number;
[ 1 : max number ]INT g2; # table of G values: g2[n] = G(2n) #
# construct the table of G values #
FOR n TO UPB g2 DO g2[ n ] := 0 OD;
g2[ 2 ] := 1; # 4 is the only sum of two even primes #
FOR n FROM 2 TO UPB prime list DO
INT p = prime list[ n ];
g2[ p ] +:= 1;
FOR m FROM n + 1 TO UPB prime list
WHILE INT sum = p + prime list[ m ];
sum <= max number
DO
g2[ sum OVER 2 ] +:= 1
OD
OD;
# show the first hundred G values #
FOR n FROM 2 TO 101 DO
print( ( whole( g2[ n ], -4 ) ) );
IF ( n - 1 ) MOD 10 = 0 THEN print( ( newline ) ) FI
OD;
# G( 1 000 000 ) #
print( ( "G(", whole( max number, 0 ), "): "
, whole( g2[ max number OVER 2 ], 0 )
, newline
)
);
# find the maximum value of G up to the maximum plot size #
INT max plot = 2000;
INT max g := 0;
FOR n TO max plot OVER 2 DO
IF g2[ n ] > max g THEN max g := g2[ n ] FI
OD;
# draw an ASCII scatter plot of G, each position represents 10 G values #
# the vertical axis is n, the horizontal axis is G(n) #
INT plot step = 10;
STRING plot value = " .-+=*%$&#@";
FOR g BY plot step TO ( max plot OVER 2 ) - plot step DO
[ 0 : max g ]INT values;
FOR v pos FROM LWB values TO UPB values DO values[ v pos ] := 0 OD;
INT max v := 0;
FOR g element FROM g TO g + ( plot step - 1 ) DO
INT g2 value = g2[ g element ];
values[ g2 value ] +:= 1;
IF g2 value > max v THEN max v := g2 value FI
OD;
print( ( IF g MOD 100 = 1 THEN "+" ELSE "|" FI ) );
FOR v pos FROM LWB values TO max v DO
print( ( plot value[ values[ v pos ] + 1 ] ) )
OD;
print( ( newline ) )
OD
END</lang>
{{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
G(1000000): 5402
</pre><span style="font-size 8px"><pre>
+.=*
| +*-
| +=-.
| ...=-.
| .-+....
| .=.- . .
| ..-.-...
| .-. + -.
| .-- ... ..
| ...+. . -
+ .+.- .. .
| + + .. . .
| . -+. . -
| -.- . . - .
| + ... .. . .
| .--.. - .
| .. ..- . .. .
| -+ . .. . .
| - .. .- - .
| . ..-. . . . .
+ .+ - . .. .
| . -..- . -
| . +- . . . .
| ..-.. .. ..
| . . +. . .-
| - -- . . . .
| . .-. . . .. .
| .+ . .. - .
| ..-. . . . . .
| -. -. . . . .
+ .... ... -.
| . . ..... . . .
| . ... . . . . . .
| . .... - . . .
| . . + . . - .
| ...... . . . .
| .+ .. . . -
| .. ..- . . . .
| ..-. . ... .
| -. .. .. . . .
+ . -.. - . . .
| ... .- . .. .
| . .-.. . .. .
| . -.. . . . . .
| .-.. . . . . .
| - .. . . - ..
| .+ - . . . .
| ... .. . .. . .
| .-.. .. . . .
| . - . . . . . . .
+ + . . . . . . .
| - .. ... . . .
| .+ . . . . . .
| .. -. . . .. .
| - .. . . . .. .
| . ...- . . . .
| .. .- . . . . .
| .. . . .. . . . .
| .. - ... . . .
| - .- . . . . .
+ .... .. . .. .
| . - - . . . . .
| .. - . . .. . .
| .. .-- . -
| . .. - . . . . .
| .- .. . - . .
| .. -.. . . . .
| .- .. . . . . .
| . =. . .. .
| - + . . .. .
+ . . . . . . . .. .
| -- . . . . . .
| . ... .. . . ..
| . ... .. . . . .
| . ... .. . - .
| . ..- . . . . .
| . .-. . ... .
| . .. . .. . . . .
| . .. .. . . . . .
| ..... . . . . .
+ . . . . . . . - .
| . - . - . . . .
| .-- . . . . .
| - . .. . .. . .
| . . . .. . . . ..
| . .. - . . . . .
| . . . . .. . . . .
| - . . . . . . -
| ... ... . . . .
| . . .. - . . . .
+ .- - . . - .
| . ... .. . . . .
| -. - . - . .
| . . . . . . . . . .
| . . .- .. . . .
| . - .- . . . .
| . - .. . . . . .
| . ... .. . . . .
| . . -. . . . . .
</pre></span>


=={{header|Arturo}}==
=={{header|Arturo}}==
Line 67: Line 243:


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]
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|Julia}}==
=={{header|Julia}}==