How to resolve the algorithm Gapful numbers step by step in the XBS programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Gapful numbers step by step in the XBS 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 XBS programming language

Source code in the xbs programming language

func isgapful(n:number):boolean{
	set s:string = tostring(n);
	set d = toint(`{s::at(0)}{s::at(?s-1)}`);
	send (n%d)==0
}

func findGapfulNumbers(start,amount){
	set gapful=[];
	set ind = start;
	while(true){
		if(isgapful(ind)){
			gapful::insert(ind);
		}
		ind++;
		if((?gapful)>=amount){
			stop;
		}
	}
	log(`First {amount} gapful ints at {start}: {gapful::join(", ")}`);
}

findGapfulNumbers(100,30);
findGapfulNumbers(1000000,15);
findGapfulNumbers(1000000000,15);

  

You may also check:How to resolve the algorithm Bitmap/Flood fill step by step in the MiniScript programming language
You may also check:How to resolve the algorithm Greatest subsequential sum step by step in the 11l programming language
You may also check:How to resolve the algorithm Logistic curve fitting in epidemiology step by step in the Java programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the Clojure programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Go programming language