Eban numbers: Difference between revisions

(→‎{{header|Perl 6}}: Fix error in assumptions. e-ban numbers were correct, but the algorithm needed some tweaks for the general case.)
Line 632:
...
Up to and including one hundred centillion: 35,184,372,088,831,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999</pre>
 
=={{header|Phix}}==
Why count when you can calculate?
<lang Phix>function count_eban(integer p10)
-- returns the count of eban numbers 1..power(10,p10)
integer n = p10-floor(p10/3),
p5 = floor(n/2),
p4 = floor((n+1)/2)
return power(5,p5)*power(4,p4)-1
end function
 
function eban(integer n)
-- returns true if n is an eban number (only fully tested to 10e9)
if n=0 then return false end if
while n do
integer thou = remainder(n,1000)
if floor(thou/100)!=0 then return false end if
if not find(floor(thou/10),{0,3,4,5,6}) then return false end if
if not find(remainder(thou,10),{0,2,4,6}) then return false end if
n = floor(n/1000)
end while
return true
end function
 
sequence s = {}
for i=0 to 1000 do
if eban(i) then s &= i end if
end for
printf(1,"eban to 1000 : %v (%d items)\n",{s,length(s)})
s = {}
for i=1000 to 4000 do
if eban(i) then s &= i end if
end for
printf(1,"eban 1000..4000 : %v (%d items)\n\n",{s,length(s)})
 
atom t0 = time()
for i=0 to 21 do
printf(1,"count_eban(10^%d) : %,d\n",{i,count_eban(i)})
end for
?elapsed(time()-t0)</lang>
{{out}}
<pre>
eban to 1000 : {2,4,6,30,32,34,36,40,42,44,46,50,52,54,56,60,62,64,66} (19 items)
eban 1000..4000 : {2000,2002,2004,2006,2030,2032,2034,2036,2040,2042,2044,2046,2050,2052,2054,2056,2060,2062,2064,2066,4000} (21 items)
 
count_eban(10^0) : 0
count_eban(10^1) : 3
count_eban(10^2) : 19
count_eban(10^3) : 19
count_eban(10^4) : 79
count_eban(10^5) : 399
count_eban(10^6) : 399
count_eban(10^7) : 1,599
count_eban(10^8) : 7,999
count_eban(10^9) : 7,999
count_eban(10^10) : 31,999
count_eban(10^11) : 159,999
count_eban(10^12) : 159,999
count_eban(10^13) : 639,999
count_eban(10^14) : 3,199,999
count_eban(10^15) : 3,199,999
count_eban(10^16) : 12,799,999
count_eban(10^17) : 63,999,999
count_eban(10^18) : 63,999,999
count_eban(10^19) : 255,999,999
count_eban(10^20) : 1,279,999,999
count_eban(10^21) : 1,279,999,999
"0.0s"
</pre>
 
=={{header|REXX}}==
7,820

edits