How to resolve the algorithm Self-describing numbers step by step in the zkl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Self-describing numbers step by step in the zkl programming language
Table of Contents
Problem Statement
There are several so-called "self-describing" or "self-descriptive" integers. An integer is said to be "self-describing" if it has the property that, when digit positions are labeled 0 to N-1, the digit in each position is equal to the number of times that that digit appears in the number. For example, 2020 is a four-digit self describing number:
Self-describing numbers < 100.000.000 are: 1210, 2020, 21200, 3211000, 42101000.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Self-describing numbers step by step in the zkl programming language
Source code in the zkl programming language
fcn isSelfDescribing(n){
if (n.bitAnd(1)) return(False); // Wikipedia: last digit must be zero
nu:= n.toString();
ns:=["0".."9"].pump(String,nu.inCommon,"len"); //"12233".inCommon("2")-->"22"
(nu+"0000000000")[0,10] == ns; //"2020","2020000000"
}
//[1..0x4_000_000].filter(isSelfDescribing).println();
const N=0d500_000;
[1..0d100_000_000, N] // chunk and thread, 200 in this case
.apply(fcn(n){ n.filter(N,isSelfDescribing) }.future)
.filter().apply("noop").println();
You may also check:How to resolve the algorithm 100 doors step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Sorting algorithms/Merge sort step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Text processing/1 step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Address of a variable step by step in the Sidef programming language
You may also check:How to resolve the algorithm Find limit of recursion step by step in the Modula-2 programming language