How to resolve the algorithm Gapful numbers step by step in the Frink programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Gapful numbers step by step in the Frink 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 Frink programming language
Source code in the frink programming language
// Create function to calculate gapful number
gapful[num,totalCounter] :=
{
// Display a line explaining the current calculation.
println["First $totalCounter gapful numbers over $num:"]
// Start a counter to compare with the total count.
counter = 0
while counter < totalCounter
{
numStr = toString[num] // Convert the integer to a string
gapfulNumStr = left[numStr,1] + right[numStr,1] // Concatenate the first and last character of the number to form a two digit number
gapfulNumInt = parseInt[gapfulNumStr] // Turn the concatenated string back into an integer.
// If the concatenated two digit integer divides into the current num variable with no remainder, print it to the list and increase our counter
if num mod gapfulNumInt == 0
{
print[numStr + " "]
counter = counter + 1
}
// Increase the current number for the next cycle.
num = num + 1
}
p
rintln[] // Linkbreak
}
// Print the first 30 gapful numbers over 100, the top 15 over 1,000,000 and the first 10 over 1,000,000,000.
gapful[100,30]
gapful[1000000,15]
gapful[1000000000,10]
You may also check:How to resolve the algorithm Naming conventions step by step in the REXX programming language
You may also check:How to resolve the algorithm Documentation step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm Text processing/Max licenses in use step by step in the JavaScript programming language
You may also check:How to resolve the algorithm HTTP step by step in the Ol programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Kitten programming language