How to resolve the algorithm Goldbach's comet step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Goldbach's comet step by step in the Raku programming language

Table of Contents

Problem Statement

Goldbach's comet is the name given to a plot of the function g(E), the so-called Goldbach function. The Goldbach function is studied in relation to Goldbach's conjecture. The function g(E) is defined for all even integers E>2 to be the number of different ways in which E can be expressed as the sum of two primes.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Goldbach's comet step by step in the Raku programming language

Source code in the raku programming language

sub G (Int $n) { +(2..$n/2).grep: { .is-prime && ($n - $_).is-prime } }

# Task
put "The first 100 G values:\n", (^100).map({ G 2 × $_ + 4 }).batch(10)».fmt("%2d").join: "\n";

put "\nG 1_000_000 = ", G 1_000_000;

# Stretch
use SVG;
use SVG::Plot;

my @x = map 2 × * + 4, ^2000;
my @y = @x.map: &G;

'Goldbachs-Comet-Raku.svg'.IO.spurt: SVG.serialize: SVG::Plot.new(
    width       => 1000,
    height      => 500,
    background  => 'white',
    title       => "Goldbach's Comet",
    x           => @x,
    values      => [@y,],
).plot: :points;


  

You may also check:How to resolve the algorithm Bitwise operations step by step in the Seed7 programming language
You may also check:How to resolve the algorithm Environment variables step by step in the Oforth programming language
You may also check:How to resolve the algorithm Pascal's triangle step by step in the IDL programming language
You may also check:How to resolve the algorithm Spiral matrix step by step in the PowerShell programming language
You may also check:How to resolve the algorithm HTTP step by step in the Emacs Lisp programming language