How to resolve the algorithm Factors of an integer step by step in the Aikido programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Factors of an integer step by step in the Aikido programming language

Table of Contents

Problem Statement

Compute the   factors   of a positive integer. These factors are the positive integers by which the number being factored can be divided to yield a positive integer result. (Though the concepts function correctly for zero and negative integers, the set of factors of zero has countably infinite members, and the factors of negative integers can be obtained from the factors of related positive numbers without difficulty;   this task does not require handling of either of these cases). Note that every prime number has two factors:   1   and itself.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Factors of an integer step by step in the Aikido programming language

Source code in the aikido programming language

import math

function factor (n:int) {
    var result = []
    function append (v) {
        if (!(v in result)) {
            result.append (v)
        }
    }
    var sqrt = cast(Math.sqrt (n))
    append (1)
    for (var i = n-1 ; i >= sqrt ; i--) {
        if ((n % i) == 0) {
            append (i)
            append (n/i)
        }
    }
    append (n)
    return result.sort()
}

function printvec (vec) {
    var comma = ""
    print ("[")
    foreach v vec {
        print (comma + v)
        comma = ", "
    }
    println ("]")
}

printvec (factor (45))
printvec (factor (25))
printvec (factor (100))

  

You may also check:How to resolve the algorithm Stack traces step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Quickselect algorithm step by step in the Fortran programming language
You may also check:How to resolve the algorithm Julia set step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm Memory allocation step by step in the C programming language
You may also check:How to resolve the algorithm Balanced brackets step by step in the Brat programming language