How to resolve the algorithm Pythagorean quadruples step by step in the Crystal programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pythagorean quadruples step by step in the Crystal 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 Crystal programming language
Source code in the crystal programming language
n = 2200
l_add, l = Hash(Int32, Bool).new(false), Hash(Int32, Bool).new(false)
(1..n).each do |x|
x2 = x * x
(x..n).each { |y| l_add[x2 + y * y] = true }
end
s = 3
(1..n).each do |x|
s1 = s
s += 2
s2 = s
((x+1)..n).each do |y|
l[y] = true if l_add[s1]
s1 += s2
s2 += 2
end
end
puts (1..n).reject{ |x| l[x] }.join(" ")
squares = (0..).each.map { |n| 2_u64**n }
squares5 = (0..).each.map { |n| 2_u64**n * 5 }
n = squares.next.as(Int)
m = squares5.next.as(Int)
pyth_quad = Iterator.of do
if n < m
value = n
n = squares.next.as(Int)
else
value = m
m = squares5.next.as(Int)
end
value
end
puts pyth_quad.take_while { |n| n <= 1000000000 }.join(" ")
You may also check:How to resolve the algorithm Catamorphism step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm SOAP step by step in the Raku programming language
You may also check:How to resolve the algorithm Rosetta Code/Rank languages by popularity step by step in the Objeck programming language
You may also check:How to resolve the algorithm Home primes step by step in the Java programming language
You may also check:How to resolve the algorithm Array concatenation step by step in the ActionScript programming language