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

Published on 12 May 2024 09:40 PM

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

Table of Contents

Problem Statement

A positive integer n is said to be a Rhonda number to base b if the product of the base b digits of n is equal to b times the sum of n's prime factors.

These numbers were named by Kevin Brown after an acquaintance of his whose residence number was 25662, a member of the base 10 numbers with this property.

25662 is a Rhonda number to base-10. The prime factorization is 2 × 3 × 7 × 13 × 47; the product of its base-10 digits is equal to the base times the sum of its prime factors: 2 × 5 × 6 × 6 × 2 = 720 = 10 × (2 + 3 + 7 + 13 + 47) Rhonda numbers only exist in bases that are not a prime. Rhonda numbers to base 10 always contain at least 1 digit 5 and always contain at least 1 even digit.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Rhonda numbers step by step in the Wren programming language

Source code in the wren programming language

import "./math" for Math, Int, Nums
import "./fmt" for Fmt, Conv

for (b in 2..36) {
    if (Int.isPrime(b)) continue
    var count = 0
    var rhonda = []
    var n = 1
    while (count < 15) {
        var digits = Int.digits(n, b)
        if (!digits.contains(0)) {
            if (b != 10 || (digits.contains(5) && digits.any { |d| d % 2 == 0 })) {
                var calc1 = Nums.prod(digits)
                var calc2 = b * Nums.sum(Int.primeFactors(n))
                if (calc1 == calc2) {
                    rhonda.add(n)
                    count = count + 1
                }
            }
        }
        n = n + 1
    }
    if (rhonda.count > 0) {
        System.print("\nFirst 15 Rhonda numbers in base %(b):")
        var rhonda2 = rhonda.map { |r| r.toString }.toList
        var rhonda3 = rhonda.map { |r| Conv.Itoa(r, b) }.toList
        var maxLen2 = Nums.max(rhonda2.map { |r| r.count })
        var maxLen3 = Nums.max(rhonda3.map { |r| r.count })
        var maxLen  = Math.max(maxLen2, maxLen3) + 1
        Fmt.print("In base 10:  $*s", maxLen, rhonda2)
        Fmt.print("In base $-2d:  $*s", b, maxLen, rhonda3)
    }
}

  

You may also check:How to resolve the algorithm Sum of squares step by step in the CLU programming language
You may also check:How to resolve the algorithm Program termination step by step in the DBL programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Haskell programming language
You may also check:How to resolve the algorithm Sokoban step by step in the Ruby programming language
You may also check:How to resolve the algorithm Sum multiples of 3 and 5 step by step in the ALGOL 68 programming language