Goldbach's comet: Difference between revisions

(Added Perl)
(→‎{{header|Perl}}: Added image)
Line 469:
=={{header|Perl}}==
{{libheader|ntheory}}
<lang perl>seuse strict;
use warnings;
use feature 'say';
 
use List::Util 'max';
use GD::Graph::bars;
use ntheory 'is_prime';
 
Line 483 ⟶ 484:
}
 
my(@x, @y);
push @x = mapy, G(2 * $_ + 4,) for my @x = 0..991999;
push @y, G($_) for @x;
 
say $_ for table 10, @y;
printf "G $_: %d", G($_) for 1e6;</lang>
 
my @data = ( \@x, \@y);
my $graph = GD::Graph::bars->new(1200, 400);
$graph->set(
title => q/Goldbach's Comet/,
y_max_value => 170,
x_tick_number => 10,
r_margin => 10,
dclrs => [ 'blue' ],
) or die $graph->error;
my $gd = $graph->plot(\@data) or die $graph->error;
 
open my $fh, '>', 'goldbachs-comet.png';
binmode $fh;
print $fh $gd->png();
close $fh;</lang>
{{out}}
<pre> 1 1 1 2 1 2 2 2 2 3
2,392

edits