Self-describing numbers: Difference between revisions
Content added Content deleted
m (fixed a bullet.) |
No edit summary |
||
Line 1,864: | Line 1,864: | ||
'''output''' is the same as the 1<sup>st</sup> REXX example. |
'''output''' is the same as the 1<sup>st</sup> REXX example. |
||
<br><br> |
<br><br> |
||
=={{header|Ring}}== |
|||
<lang ring> |
|||
# Project : Self-describing numbers |
|||
# Date : 2017/11/18 |
|||
# Author : Gal Zsolt (~ CalmoSoft ~) |
|||
# Email : <calmosoft@gmail.com> |
|||
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 |
|||
</lang> |
|||
Output: |
|||
<pre> |
|||
1210 |
|||
2020 |
|||
21200 |
|||
3211000 |
|||
42101000 |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |