How to resolve the algorithm Idoneal numbers step by step in the jq programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Idoneal numbers step by step in the jq programming language
Table of Contents
Problem Statement
Idoneal numbers (also called suitable numbers or convenient numbers) are the positive integers D such that any integer expressible in only one way as x2 ± Dy2 (where x2 is relatively prime to Dy2) is a prime power or twice a prime power. A positive integer n is idoneal if and only if it cannot be written as ab + bc + ac for distinct positive integers a, b, and c with 0 < a < b < c. There are only 65 known iodoneal numbers and is likely that no others exist. If there are others, it has been proven that there are at most, two more, and that no others exist below 1,000,000.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Idoneal numbers step by step in the jq programming language
Source code in the jq programming language
# For gojq:
# def _nwise($n):
# def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
# n;
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .;
def isIdoneal:
first(
label $out
| . as $n
| range(1; $n) as $a
| label $startB
| range($a+1; $n) as $b
| ($a+$b) as $sum
| ($a*$b) as $prod
| if $prod + $sum > $n then break $startB
else label $startC
| range($b+1; $n) as $c
| ($prod + $sum*$c) as $x
| if $x == $n then 0, break $out
elif $x > $n then break $startC
else empty
end
end )
// true | if . == 0 then false else . end;
# Search blindly
def idoneals: range(1; infinite) | select(isIdoneal);
# The task:
[limit(65; idoneals)]
| _nwise(13) | map(lpad(5)) | join(" ")
You may also check:How to resolve the algorithm Binary digits step by step in the COBOL programming language
You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the Delphi programming language
You may also check:How to resolve the algorithm Two's complement step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Sorting algorithms/Selection sort step by step in the Run BASIC programming language
You may also check:How to resolve the algorithm Proper divisors step by step in the zkl programming language