Narcissistic decimal number: Difference between revisions

→‎Simple Version: upper limit is 18 digits not 19, no need to multiply with 1
(added ZX Spectrum Basic)
(→‎Simple Version: upper limit is 18 digits not 19, no need to multiply with 1)
Line 1,063:
=={{header|FreeBASIC}}==
===Simple Version===
<lang FreeBASIC>' normal version: 1714-0603-20152017
' compile with: fbc -s console
' can go up to 1918 digits (ulongint is 64bit), above 1918 overflow will occur
 
Dim As Integer n, n0, n1, n2, n3, n4, n5, n6, n7, n8, n9, a, b
Dim As Integer d()
Line 1,072:
Dim As ULongInt x
Dim As String str_x
 
For n = 1 To 7
For n9 = n To 0 Step -1
Line 1,084:
For n1 = n-n9-n8-n7-n6-n5-n4-n3-n2 To 0 Step -1
n0 = n-n9-n8-n7-n6-n5-n4-n3-n2-n1
 
x = n1*d2pow(1) + n2*d2pow(2) + n3*d2pow(3) + n4*d2pow(4) + n5*d2pow(5)_
+ n6*d2pow(6) + n7*d2pow(7) + n8*d2pow(8) + n9*d2pow(9)
 
str_x = Str(x)
If Len(str_x) = n Then
 
ReDim d(10)
For a = 0 To n-1
d(Str_x[a]- Asc("0")) += 1
Next a
 
If n0 = d(0) AndAlso n1 = d(1) AndAlso n2 = d(2) AndAlso n3 = d(3)_
AndAlso n4 = d(4) AndAlso n5 = d(5) AndAlso n6 = d(6)_
Line 1,102:
End If
End If
 
Next n1
Next n2
Line 1,112:
Next n8
Next n9
 
For a As Integer = 2 To 9
d2pow(a) = d2pow(a) * a
Next a
 
Next n
 
' empty keyboard buffer
While InKey <> "" : Wend
457

edits