Self-describing numbers: Difference between revisions

(→‎{{header|Haskell}}: Extended range up to 42101000)
Line 992:
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
<lang julia>function selfie(x)
 
y = reverse(digits(x))
<lang julia>function selfie(x::Integer)
len = length(y)
yds = reverse(digits(x))
if sum(yds) != len &&length(ds) return false end
for i = 1:len
for (i, d) in enumerate(ds)
y[i]if d != sum(yds .== i - 1) && return false end
end
return true
end</lang>
{{out}}
<pre>julia> selfie(2020)
true
 
julia>@show selfie(20212020)
@show selfie(2021)
false
 
julia> selfies(x) = for i =in 1:x selfie(i) && println(i) end
julia> @time selfies(4000000)</lang>
# methods for generic function selfies
selfies(x) at none:1
 
{{out}}
julia> @time selfies(4000000)
<pre>1210
2020
21200
3211000
elapsed time: 1.901413209398922 seconds (8.01 M allocations: 1.049 GiB, 6.91% gc time)</pre>
 
=={{header|K}}==
Anonymous user