How to resolve the algorithm Self-describing numbers step by step in the Ring programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Self-describing numbers step by step in the Ring 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 Ring programming language
Source code in the ring programming language
# Project : Self-describing numbers
for num = 1 to 45000000
res = 0
for n=1 to len(string(num))
temp = string(num)
pos = number(temp[n])
cnt = count(temp,string(n-1))
if cnt = pos
res = res + 1
ok
next
if res = len(string(num))
see num + nl
ok
next
func count(cString,dString)
sum = 0
while substr(cString,dString) > 0
sum = sum + 1
cString = substr(cString,substr(cString,dString)+len(string(sum)))
end
return sum
You may also check:How to resolve the algorithm Infinity step by step in the Pascal programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the IWBASIC programming language
You may also check:How to resolve the algorithm Enumerations step by step in the Oforth programming language
You may also check:How to resolve the algorithm Top rank per group step by step in the Elixir programming language
You may also check:How to resolve the algorithm Repeat step by step in the Phix programming language