Jump to content

Self-describing numbers: Difference between revisions

No edit summary
Line 89:
 
=={{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}}==
477

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.