How to resolve the algorithm Gapful numbers step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Gapful numbers step by step in the Wren programming language
Table of Contents
Problem Statement
Numbers (positive integers expressed in base ten) that are (evenly) divisible by the number formed by the first and last digit are known as gapful numbers.
Evenly divisible means divisible with no remainder.
All one─ and two─digit numbers have this property and are trivially excluded. Only numbers ≥ 100 will be considered for this Rosetta Code task.
187 is a gapful number because it is evenly divisible by the number 17 which is formed by the first and last decimal digits of 187.
About 7.46% of positive integers are gapful.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Gapful numbers step by step in the Wren programming language
Source code in the wren programming language
import "./fmt" for Fmt
var starts = [1e2, 1e6, 1e7, 1e9, 7123]
var counts = [30, 15, 15, 10, 25]
for (i in 0...starts.count) {
var count = 0
var j = starts[i]
var pow = 100
while (true) {
if (j < pow * 10) break
pow = pow * 10
}
System.print("First %(counts[i]) gapful numbers starting at %(Fmt.dc(0, starts[i]))")
while (count < counts[i]) {
var fl = (j/pow).floor*10 + (j % 10)
if (j%fl == 0) {
System.write("%(j) ")
count = count + 1
}
j = j + 1
if (j >= 10*pow) pow = pow * 10
}
System.print("\n")
}
You may also check:How to resolve the algorithm Random numbers step by step in the ERRE programming language
You may also check:How to resolve the algorithm Levenshtein distance step by step in the IS-BASIC programming language
You may also check:How to resolve the algorithm Sum of squares step by step in the REXX programming language
You may also check:How to resolve the algorithm Hello world/Web server step by step in the Rust programming language
You may also check:How to resolve the algorithm Permutations/Derangements step by step in the Acornsoft Lisp programming language