Self-describing numbers: Difference between revisions
Content added Content deleted
Catskill549 (talk | contribs) No edit summary |
Catskill549 (talk | contribs) |
||
Line 89: | Line 89: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<lang AWK> |
|||
# syntax: GAWK -f SELF-DESCRIBING_NUMBERS.AWK |
|||
# contributed by Dan Nielsen |
|||
BEGIN { |
|||
for (n=1; n<=100000000; n++) { |
|||
if (is_self_describing(n)) { |
|||
print(n) |
|||
} |
|||
} |
|||
exit(0) |
|||
} |
|||
function is_self_describing(n, i) { |
|||
for (i=1; i<=length(n); i++) { |
|||
if (substr(n,i,1) != gsub(i-1,"&",n)) { |
|||
return(0) |
|||
} |
|||
} |
|||
return(1) |
|||
} |
|||
</lang> |
|||
<p>output:</p> |
|||
<pre> |
|||
1210 |
|||
2020 |
|||
21200 |
|||
3211000 |
|||
42101000 |
|||
</pre> |
|||
=={{header|BASIC}}== |
=={{header|BASIC}}== |