How to resolve the algorithm Pythagorean quadruples step by step in the D programming language

Published on 12 May 2024 09:40 PM
#D

How to resolve the algorithm Pythagorean quadruples step by step in the D programming language

Table of Contents

Problem Statement

One form of   Pythagorean quadruples   is   (for positive integers   a,   b,   c,   and   d):

An example:

For positive integers up   2,200   (inclusive),   for all values of   a,   b,   c,   and   d, find   (and show here)   those values of   d   that   can't   be represented. Show the values of   d   on one line of output   (optionally with a title).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Pythagorean quadruples step by step in the D programming language

Source code in the d programming language

import std.bitmanip : BitArray;
import std.stdio;

enum N = 2_200;
enum N2 = 2*N*N;

void main() {
    BitArray found;
    found.length = N+1;

    BitArray aabb;
    aabb.length = N2+1;

    uint s=3;

    for (uint a=1; a<=N; ++a) {
        uint aa = a*a;
        for (uint b=1; b<N; ++b) {
            aabb[aa + b*b] = true;
        }
    }

    for (uint c=1; c<=N; ++c) {
        uint s1 = s;
        s += 2;
        uint s2 = s;
        for (uint d=c+1; d<=N; ++d) {
            if (aabb[s1]) {
                found[d] = true;
            }
            s1 += s2;
            s2 += 2;
        }
    }

    writeln("The values of d <= ", N, " which can't be represented:");
    for (uint d=1; d<=N; ++d) {
        if (!found[d]) {
            write(d, ' ');
        }
    }
    writeln;
}


  

You may also check:How to resolve the algorithm Hello world/Text step by step in the TailDot programming language
You may also check:How to resolve the algorithm Negative base numbers step by step in the F# programming language
You may also check:How to resolve the algorithm Sorting algorithms/Comb sort step by step in the Python programming language
You may also check:How to resolve the algorithm FTP step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Damm algorithm step by step in the Phix programming language