How to resolve the algorithm Composite numbers k with no single digit factors whose factors are all substrings of k step by step in the Wren programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Composite numbers k with no single digit factors whose factors are all substrings of k step by step in the Wren programming language

Table of Contents

Problem Statement

Find the composite numbers k in base 10, that have no single digit prime factors and whose prime factors are all a substring of k.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Composite numbers k with no single digit factors whose factors are all substrings of k step by step in the Wren programming language

Source code in the wren programming language

import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt

var count = 0
var k = 11 * 11
var res = []
while (count < 20) {
    if (k % 3 == 0 || k % 5 == 0 || k % 7 == 0) {
        k = k + 2
        continue
    }
    var factors = Int.primeFactors(k)
    if (factors.count > 1) {
        Lst.prune(factors)
        var s = k.toString
        var includesAll = true
        for (f in factors) {
            if (s.indexOf(f.toString) == -1) {
                includesAll = false
                break
            }
        }
        if (includesAll) {
            res.add(k)
            count = count + 1
        }
    }
    k = k + 2
}
Fmt.print("$,10d", res[0..9])
Fmt.print("$,10d", res[10..19])


  

You may also check:How to resolve the algorithm Move-to-front algorithm step by step in the Racket programming language
You may also check:How to resolve the algorithm Hough transform step by step in the Go programming language
You may also check:How to resolve the algorithm Taxicab numbers step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Narcissistic decimal number step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Maze generation step by step in the PureBasic programming language