How to resolve the algorithm Self-describing numbers step by step in the J programming language

Published on 12 May 2024 09:40 PM
#J

How to resolve the algorithm Self-describing numbers step by step in the J 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 J programming language

Source code in the j programming language

   digits   =: 10&#.^:_1
   counts   =: _1 + [: #/.~ i.@:# , ]
   selfdesc =: = counts&.digits"0       NB.  Note use of "under"


   selfdesc 2020 1210 21200 3211000 43101000 42101000
1 1 1 1 0 1


   I.@:selfdesc i. 1e6
1210 2020 21200


  

You may also check:How to resolve the algorithm Handle a signal step by step in the Swift programming language
You may also check:How to resolve the algorithm Isqrt (integer square root) of X step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the Babel programming language
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Hash join step by step in the Racket programming language