How to resolve the algorithm Pythagorean quadruples step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pythagorean quadruples step by step in the zkl 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 zkl programming language
Source code in the zkl programming language
# find values of d where d^2 =/= a^2 + b^2 + c^2 for any integers a, b, c #
# where d in [1..2200], a, b, c =/= 0 #
# max number to check #
const max_number = 2200;
const max_square = max_number * max_number;
# table of numbers that can be the sum of two squares #
sum_of_two_squares:=Data(max_square+1,Int).fill(0); # 4 meg byte array
foreach a in ([1..max_number]){
a2 := a * a;
foreach b in ([a..max_number]){
sum2 := ( b * b ) + a2;
if(sum2 <= max_square) sum_of_two_squares[ sum2 ] = True; # True-->1
}
}
# now find d such that d^2 - c^2 is in sum of two squares #
solution:=Data(max_number+1,Int).fill(0); # another byte array
foreach d in ([1..max_number]){
d2 := d * d;
foreach c in ([1..d-1]){
diff2 := d2 - ( c * c );
if(sum_of_two_squares[ diff2 ]){ solution[ d ] = True; break; }
}
}
# print the numbers whose squares are not the sum of three squares #
foreach d in ([1..max_number]){
if(not solution[ d ]) print(d, " ");
}
println();
You may also check:How to resolve the algorithm Longest common substring step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Binary digits step by step in the REXX programming language
You may also check:How to resolve the algorithm First perfect square in base n with n unique digits step by step in the Perl programming language
You may also check:How to resolve the algorithm Detect division by zero step by step in the MUMPS programming language
You may also check:How to resolve the algorithm Sum of a series step by step in the Clojure programming language