23 lines
609 B
Text
23 lines
609 B
Text
' 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
|