How to resolve the algorithm Count in factors step by step in the Wren programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Count in factors step by step in the Wren programming language

Table of Contents

Problem Statement

Write a program which counts up from   1,   displaying each number as the multiplication of its prime factors. For the purpose of this task,   1   (unity)   may be shown as itself.

2   is prime,   so it would be shown as itself.       6   is not prime;   it would be shown as

2 × 3

{\displaystyle 2\times 3}

. 2144   is not prime;   it would be shown as

2 × 2 × 2 × 2 × 2 × 67

{\displaystyle 2\times 2\times 2\times 2\times 2\times 67}

.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Count in factors step by step in the Wren programming language

Source code in the wren programming language

import "./math" for Int

for (r in [1..9, 2144..2154, 9987..9999]) {    
    for (i in r) {
        var factors = (i > 1) ? Int.primeFactors(i) : [1]
        System.print("%(i): %(factors.join(" x "))")
    }
    System.print()
}


  

You may also check:How to resolve the algorithm Binary digits step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Stair-climbing puzzle step by step in the Oz programming language
You may also check:How to resolve the algorithm Factorial step by step in the Groovy programming language
You may also check:How to resolve the algorithm Runge-Kutta method step by step in the PL/I programming language
You may also check:How to resolve the algorithm Substring step by step in the Nim programming language