How to resolve the algorithm Inconsummate numbers in base 10 step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Inconsummate numbers in base 10 step by step in the Wren programming language
Table of Contents
Problem Statement
A consummate number is a non-negative integer that can be formed by some integer N divided by the the digital sum of N.
47 is a consummate number. On the other hand, there are integers that can not be formed by a ratio of any integer over its digital sum. These numbers are known as inconsummate numbers.
62 is an inconsummate number. There is no integer ratio of an integer to its digital sum that will result in 62. The base that a number is expressed in will affect whether it is inconsummate or not. This task will be restricted to base 10.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Inconsummate numbers in base 10 step by step in the Wren programming language
Source code in the wren programming language
import "./math" for Int
import "./fmt" for Fmt
// Maximum ratio for 6 digit numbers is 100,000
var cons = List.filled(100001, false)
for (i in 1..999999) {
var ds = Int.digitSum(i)
var ids = i/ds
if (ids.isInteger) cons[ids] = true
}
var incons = []
for (i in 1...cons.count) {
if (!cons[i]) incons.add(i)
}
System.print("First 50 inconsummate numbers in base 10:")
Fmt.tprint("$3d", incons[0..49], 10)
Fmt.print("\nOne thousandth: $,d", incons[999])
import "./math" for Int, Nums
import "./fmt" for Fmt
var generateInconsummate = Fiber.new { |maxWanted|
var minDigitSums = (2..14).map { |i| [10.pow(i), ((10.pow(i-2) * 11 - 1) / (9 * i - 17)).floor] }
var limit = Nums.min(minDigitSums.where { |p| p[1] > maxWanted }.map { |p| p[0] })
var arr = List.filled(limit, 0)
arr[0] = 1
for (dividend in 1...limit) {
var ds = Int.digitSum(dividend)
var quo = (dividend/ds).floor
var rem = dividend % ds
if (rem == 0 && quo < limit) arr[quo] = 1
}
for (j in 0...arr.count) {
if (arr[j] == 0) Fiber.yield(j)
}
}
var incons = List.filled(50, 0)
System.print("First 50 inconsummate numbers in base 10:")
for (i in 1..100000) {
var j = generateInconsummate.call(100000)
if (i <= 50) {
incons[i-1] = j
if (i == 50) Fmt.tprint("$3d", incons, 10)
} else if (i == 1000) {
Fmt.print("\nOne thousandth $,d", j)
} else if (i == 10000) {
Fmt.print("Ten thousandth $,d", j)
} else if (i == 100000) {
Fmt.print("100 thousandth $,d", j)
}
}
You may also check:How to resolve the algorithm Write language name in 3D ASCII step by step in the Visual Basic .NET programming language
You may also check:How to resolve the algorithm Function definition step by step in the Nial programming language
You may also check:How to resolve the algorithm Repeat step by step in the REXX programming language
You may also check:How to resolve the algorithm Semiprime step by step in the Tcl programming language
You may also check:How to resolve the algorithm Long multiplication step by step in the CoffeeScript programming language