How to resolve the algorithm Self-describing numbers step by step in the Factor programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Self-describing numbers step by step in the Factor 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 Factor programming language
Source code in the factor programming language
USING: kernel math.parser prettyprint sequences ;
IN: rosetta-code.self-describing-numbers
: digits ( n -- seq ) number>string string>digits ;
: digit-count ( seq n -- m ) [ = ] curry count ;
: self-describing-number? ( n -- ? )
digits dup [ digit-count = ] with map-index [ t = ] all? ;
100,000,000 <iota> [ self-describing-number? ] filter .
You may also check:How to resolve the algorithm Floyd's triangle step by step in the Seed7 programming language
You may also check:How to resolve the algorithm HTTPS/Authenticated step by step in the LiveCode programming language
You may also check:How to resolve the algorithm Euclid-Mullin sequence step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Pythagorean triples step by step in the Mercury programming language
You may also check:How to resolve the algorithm Program name step by step in the Yabasic programming language