How to resolve the algorithm Sexy primes step by step in the XPL0 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Sexy primes step by step in the XPL0 programming language

Table of Contents

Problem Statement

In mathematics, sexy primes are prime numbers that differ from each other by six. For example, the numbers 5 and 11 are both sexy primes, because 11 minus 6 is 5. The term "sexy prime" is a pun stemming from the Latin word for six: sex. Sexy prime pairs: Sexy prime pairs are groups of two primes that differ by 6. e.g. (5 11), (7 13), (11 17) See sequences: OEIS:A023201 and OEIS:A046117 Sexy prime triplets: Sexy prime triplets are groups of three primes where each differs from the next by 6. e.g. (5 11 17), (7 13 19), (17 23 29) See sequences: OEIS:A046118, OEIS:A046119 and OEIS:A046120 Sexy prime quadruplets: Sexy prime quadruplets are groups of four primes where each differs from the next by 6. e.g. (5 11 17 23), (11 17 23 29) See sequences: OEIS:A023271, OEIS:A046122, OEIS:A046123 and OEIS:A046124 Sexy prime quintuplets: Sexy prime quintuplets are groups of five primes with a common difference of 6. One of the terms must be divisible by 5, because 5 and 6 are relatively prime. Thus, the only possible sexy prime quintuplet is (5 11 17 23 29)

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Sexy primes step by step in the XPL0 programming language

Source code in the xpl0 programming language

func IsPrime(N);        \Return 'true' if N is prime
int  N, I;
[if N <= 2 then return N = 2;
if (N&1) = 0 then \even >2\ return false;
for I:= 3 to sqrt(N) do
    [if rem(N/I) = 0 then return false;
    I:= I+1;
    ];
return true;
];

int CU, C2, C3, C4, C5, N, I;
int Unsexy(10), Pairs(5), Trips(5), Quads(5), Quins(5);
[CU:= 0;  C2:= 0;  C3:= 0;  C4:= 0;  C5:= 0;
for N:= 1000035 downto 2 do
    [if IsPrime(N) then
        [if IsPrime(N-6) then
                [if C2 < 5 then Pairs(C2):= N;
                C2:= C2+1;
                if IsPrime(N-12) then
                    [if C3 < 5 then Trips(C3):= N;
                    C3:= C3+1;
                    if IsPrime(N-18) then
                        [if C4 < 5 then Quads(C4):= N;
                        C4:= C4+1;
                        if IsPrime(N-24) then
                            [if C5 < 5 then Quins(C5):= N;
                            C5:= C5+1;
                            ];
                        ];
                    ];
                ]
        else    if not IsPrime(N+6) then
                    [if CU < 10 then Unsexy(CU):= N;
                    CU:= CU+1;
                    ];
        ];
    ];
IntOut(0, C2);  Text(0, " pairs ending with:^m^j");
for I:= 4 downto 0 do
        [Text(0, "  [");
        IntOut(0, Pairs(I)-6);  Text(0, ", ");
        IntOut(0, Pairs(I));    Text(0, "]^m^j");
        ];
IntOut(0, C3);  Text(0, " triplets ending with:^m^j");
for I:= 4 downto 0 do
        [Text(0, "  [");
        IntOut(0, Trips(I)-12);  Text(0, ", ");
        IntOut(0, Trips(I)-6);   Text(0, ", ");
        IntOut(0, Trips(I));     Text(0, "]^m^j");
        ];
IntOut(0, C4);  Text(0, " quadruplets ending with:^m^j");
for I:= 4 downto 0 do
        [Text(0, "  [");
        IntOut(0, Quads(I)-18);  Text(0, ", ");
        IntOut(0, Quads(I)-12);  Text(0, ", ");
        IntOut(0, Quads(I)-6);   Text(0, ", ");
        IntOut(0, Quads(I));     Text(0, "]^m^j");
        ];
IntOut(0, C5);  Text(0, " quintuplet(s) ending with:^m^j");
I:= if C5 > 5 then 5 else C5;
for I:= I-1 downto 0 do
        [Text(0, "  [");
        IntOut(0, Quins(I)-24);  Text(0, ", ");
        IntOut(0, Quins(I)-18);  Text(0, ", ");
        IntOut(0, Quins(I)-12);  Text(0, ", ");
        IntOut(0, Quins(I)-6);   Text(0, ", ");
        IntOut(0, Quins(I));     Text(0, "]^m^j");
        ];
IntOut(0, CU);  Text(0, " unsexy primes ending with:^m^j");
for I:= 9 downto 0 do
        [IntOut(0, Unsexy(I));  if I then Text(0, ", ")];
CrLf(0);
]

  

You may also check:How to resolve the algorithm CRC-32 step by step in the RPL programming language
You may also check:How to resolve the algorithm Hailstone sequence step by step in the ERRE programming language
You may also check:How to resolve the algorithm Multi-dimensional array step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Temperature conversion step by step in the Wren programming language
You may also check:How to resolve the algorithm Set of real numbers step by step in the Mathematica/Wolfram Language programming language