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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Factors of an integer step by step in the Arc 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 Arc programming language

Source code in the arc programming language

(= divisor (fn (num)
   (= dlist '())
   (when (is 1 num) (= dlist '(1 0)))
   (when (is 2 num) (= dlist '(2 1)))
   (unless (or (is 1 num) (is 2 num))
   (up i 1 (+ 1 (/ num 2))
     (if (is 0 (mod num i))
         (push i dlist)))
   (= dlist (cons num dlist)))
   dlist))

(map [rev _] (map [divisor _] '(45 53 60 64)))

'(
(1 3 5 9 15 45) 
(1 53) 
(1 2 3 4 5 6 10 12 15 20 30 60) 
(1 2 4 8 16 32 64)
)

  

You may also check:How to resolve the algorithm Array concatenation step by step in the 8th programming language
You may also check:How to resolve the algorithm Detect division by zero step by step in the Nanoquery programming language
You may also check:How to resolve the algorithm Bitmap/Bézier curves/Quadratic step by step in the Nim programming language
You may also check:How to resolve the algorithm Record sound step by step in the Wee Basic programming language
You may also check:How to resolve the algorithm Loops/For step by step in the 68000 Assembly programming language