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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pythagorean quadruples step by step in the Wren 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 Wren programming language

Source code in the wren programming language

var N = 2200
var N2 = N * N * 2
var s = 3
var s1 = 0
var s2 = 0
var r = List.filled(N + 1, false)
var ab = List.filled(N2 + 1, false)

for (a in 1..N) {
    var a2 = a * a
    for (b in a..N) ab[a2 + b*b] = true
}

for (c in 1..N) {
    s1 = s
    s = s + 2
    s2 = s
    var d = c + 1
    while (d <= N) {
        if (ab[s1]) r[d] = true
        s1 = s1 + s2
        s2 = s2 + 2
        d = d + 1
    }
}

for (d in 1..N) {
    if (!r[d]) System.write("%(d) ")
}
System.print()

  

You may also check:How to resolve the algorithm N-queens problem step by step in the PHP programming language
You may also check:How to resolve the algorithm Penta-power prime seeds step by step in the Wren programming language
You may also check:How to resolve the algorithm Host introspection step by step in the Ruby programming language
You may also check:How to resolve the algorithm Image noise step by step in the PL/I programming language
You may also check:How to resolve the algorithm Loops/For step by step in the REXX programming language