Self-describing numbers: Difference between revisions

Added FreeBASIC
No edit summary
(Added FreeBASIC)
Line 767:
count i c@ [char] 0 - <> if drop 2drop false unloop exit then
loop drop 2drop true ;</lang>
 
=={{header|FreeBASIC}}==
<lang freebasic>' FB 1.05.0 Win64
 
Function selfDescribing (n As UInteger) As Boolean
If n = 0 Then Return False
Dim ns As String = Str(n)
Dim count(0 To 9) As Integer '' all elements zero by default
While n > 0
count(n Mod 10) += 1
n \= 10
Wend
For i As Integer = 0 To Len(ns) - 1
If ns[i] - 48 <> count(i) Then Return False '' numerals have ascii values from 48 to 57
Next
Return True
End Function
 
Print "The self-describing numbers less than 100 million are:"
For i As Integer = 0 To 99999999
If selfDescribing(i) Then Print i; " ";
Next
Print
Print "Press any key to quit"
Sleep</lang>
 
{{out}}
<pre>
The self-describing numbers less than 100 million are:
1210 2020 21200 3211000 42101000
</pre>
 
=={{header|Go}}==
9,492

edits