How to resolve the algorithm Idoneal numbers step by step in the Wren programming language

Published on 12 May 2024 09:40 PM

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

Source code in the wren programming language

import "./fmt" for Fmt

var isIdoneal = Fn.new { |n|
    for (a in 1...n) {
        for (b in a+1...n) {
            if (a*b + a + b > n) break
            for (c in b+1...n) {
                var sum = a*b + b*c + a*c
                if (sum == n) return false
                if (sum > n) break
            }
        }
    }
    return true
}

var idoneals = []
for (n in 1..1850) if (isIdoneal.call(n)) idoneals.add(n)
Fmt.tprint("$4d", idoneals, 13)


  

You may also check:How to resolve the algorithm Scope modifiers step by step in the 68000 Assembly programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the TSE SAL programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Sorensen–Dice coefficient step by step in the Perl programming language
You may also check:How to resolve the algorithm Towers of Hanoi step by step in the C programming language