Eban numbers: Difference between revisions

→‎{{header|ALGOL 68}}: Removed unnecessary test
(Added AppleScript.)
(→‎{{header|ALGOL 68}}: Removed unnecessary test)
 
(34 intermediate revisions by 23 users not shown)
Line 32:
:*   The MathWorld entry:   [http://mathworld.wolfram.com/EbanNumber.html eban numbers].
:*   The OEIS entry:   [http://oeis.org/A006933 A6933, eban numbers].
:*   [[Number names]].
<br><br>
 
=={{header|11l}}==
{{trans|Nim}}
 
<syntaxhighlight lang="11l">F iseban(n)
I n == 0
R 0B
V (b, r) = divmod(n, 1'000'000'000)
(V m, r) = divmod(r, 1'000'000)
(V t, r) = divmod(r, 1'000)
m = I m C 30..66 {m % 10} E m
t = I t C 30..66 {t % 10} E t
r = I r C 30..66 {r % 10} E r
R Set([b, m, t, r]) <= Set([0, 2, 4, 6])
 
print(‘eban numbers up to and including 1000:’)
L(i) 0..100
I iseban(i)
print(i, end' ‘ ’)
 
print("\n\neban numbers between 1000 and 4000 (inclusive):")
L(i) 1000..4000
I iseban(i)
print(i, end' ‘ ’)
 
print()
L(maxn) (10'000, 100'000, 1'000'000, 10'000'000)
V count = 0
L(i) 0..maxn
I iseban(i)
count++
print("\nNumber of eban numbers up to and including #8: #4".format(maxn, count))</syntaxhighlight>
 
{{out}}
<pre>
eban numbers up to and including 1000:
2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
 
eban numbers between 1000 and 4000 (inclusive):
2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000
 
Number of eban numbers up to and including 10000: 79
 
Number of eban numbers up to and including 100000: 399
 
Number of eban numbers up to and including 1000000: 399
 
Number of eban numbers up to and including 10000000: 1599
</pre>
 
=={{header|ALGOL 68}}==
{{Trans|Lua|for the eban number enumerating code}}
{{Trans|Phix|for the eban number counting code}}
<syntaxhighlight lang="algol68">
BEGIN # Eban numbers - translated from the Lua and Phix samples #
 
MODE INTERVAL = STRUCT( INT start, end, BOOL print );
 
[]INTERVAL intervals = ( ( 2, 1000, TRUE )
, ( 1000, 4000, TRUE )
, ( 2, 10000, FALSE )
, ( 2, 1000000, FALSE )
, ( 2, 10000000, FALSE )
, ( 2, 100000000, FALSE )
, ( 2, 1000000000, FALSE )
);
FOR intp FROM LWB intervals TO UPB intervals DO
INTERVAL intv = intervals[ intp ];
IF start OF intv = 2 THEN
print( ( "eban numbers up to and including ", whole( end OF intv, 0 ), ":" ) )
ELSE
print( ( "eban numbers between ", whole( start OF intv, 0 )
, " and ", whole( end OF intv, 0 ), " (inclusive)"
)
)
FI;
print( ( newline ) );
 
IF NOT print OF intv THEN
# calculate the count, as in the Phix sample #
# end OF intv must be a power of 10 #
INT p10 := 0;
INT v := end OF intv;
WHILE v > p10 DO
p10 +:= 1;
v OVERAB 10
OD;
INT n = p10 - ( p10 OVER 3 );
INT p5 = n OVER 2;
INT p4 = ( n + 1 ) OVER 2;
print( ( "count = ", whole( ( ( 5 ^ p5 ) * ( 4 ^ p4 ) ) - 1, 0 ), newline ) )
ELSE
# enumerate the eban numbers, as in the Lua and other samples #
INT count := 0;
FOR i FROM start OF intv BY 2 TO end OF intv DO
INT b = i OVER 1 000 000 000;
INT r := i MOD 1 000 000 000;
INT m := r OVER 1 000 000;
r := i MOD 1 000 000;
INT t := r OVER 1 000;
r := r MOD 1 000;
IF m >= 30 AND m <= 66 THEN m MODAB 10 FI;
IF t >= 30 AND t <= 66 THEN t MODAB 10 FI;
IF r >= 30 AND r <= 66 THEN r MODAB 10 FI;
IF b = 0 OR b = 2 OR b = 4 OR b = 6 THEN
IF m = 0 OR m = 2 OR m = 4 OR m = 6 THEN
IF t = 0 OR t = 2 OR t = 4 OR t = 6 THEN
IF r = 0 OR r = 2 OR r = 4 OR r = 6 THEN
print( ( whole( i, 0 ), " " ) );
count +:= 1
FI
FI
FI
FI
OD;
print( ( newline, "count = ", whole( count, 0 ), newline ) )
FI;
print( ( newline ) )
OD
END
</syntaxhighlight>
{{out}}
<pre>
eban numbers up to and including 1000:
2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
count = 19
 
eban numbers between 1000 and 4000 (inclusive)
2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000
count = 21
 
eban numbers up to and including 10000:
count = 79
 
eban numbers up to and including 1000000:
count = 399
 
eban numbers up to and including 10000000:
count = 1599
 
eban numbers up to and including 100000000:
count = 7999
 
eban numbers up to and including 1000000000:
count = 7999
</pre>
 
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">(*
Quickly generate all the (positive) eban numbers up to and including the
This assumes either positive or negative integer input and treats 0 as "zero" rather than as "nought" or "nil".
specified end number, then lose those before the start number.
Because of AppleScript's number precision at the time of writing, the range is limited to between > -10^15 and < 10^15.
0 is taken as "zero" rather than as "nought" or "nil".
WARNING: The getEbans() handler returns a potentially very long list of numbers.
Don't let such a list get assigned to a persistent variable or be the end result displayed in an editor!
*)
 
on isEban(n)
on getEbans(startNumber, endNumber)
if (n < 2) then
script o
if (n > -2) then return false
setproperty noutput to: -1{}
property listCollector : missing value
end if
property temp : missing value
repeat 5 times -- Change to 7 times for > -10^21 to < 10^21.
end script
set x to n mod 1000
if ((x > 66) or (x mod 2 is 1) or ((x < 30) and (x > 6)) or (x mod 10 is 8)) then return false
if (startNumber > endNumber) then set {startNumber, endNumber} to {endNumber, startNumber}
set n to n div 1000
-- The range is limited to between 0 and 10^15 to keep within AppleScript's current number precision.
if (n is 0) then return true
-- Even so, some of the numbers may not /look/ right when displayed in a editor.
set limit to 10 ^ 15 - 1
if (endNumber > limit) then set endNumber to limit
if (startNumber > limit) then set startNumber to limit
-- Initialise the output list with 0 and the sub-1000 ebans, stopping if the end number's reached.
-- The 0's needed for rest of the process, but is removed at the end.
repeat with tens in {0, 30, 40, 50, 60}
repeat with units in {0, 2, 4, 6}
set thisEban to tens + units
if (thisEban ≤ endNumber) then set end of o's output to thisEban
end repeat
end repeat
return missing value -- Status unknown. Number out of range.
-- Repeatedly sweep the output list, adding new ebans formed from the addition of those found previously
end isEban
-- to a suitable power of 1000 times each one. Stop when the end number's reached or exceeded.
-- The output list may become very long and appending items to it individually take forever, so results are
-- collected in short, 1000-item lists, which are concatenated to the output at the end of each sweep.
set sweepLength to (count o's output)
set multiplier to 1000
repeat while (thisEban < endNumber) -- Per sweep.
set o's temp to {}
set o's listCollector to {o's temp}
repeat with i from 2 to sweepLength -- Per eban found already. (Not the 0.)
set baseAmount to (item i of o's output) * multiplier
repeat with j from 1 to sweepLength by 1000 -- Per 1000-item list.
set z to j + 999
if (z > sweepLength) then set z to sweepLength
repeat with k from j to z -- Per new eban.
set thisEban to baseAmount + (item k of o's output)
if (thisEban ≤ endNumber) then set end of o's temp to thisEban
if (thisEban ≥ endNumber) then exit repeat
end repeat
if (thisEban ≥ endNumber) then exit repeat
set o's temp to {}
set end of o's listCollector to o's temp
end repeat
if (thisEban ≥ endNumber) then exit repeat
end repeat
-- Concatentate this sweep's new lists together
set listCount to (count o's listCollector)
repeat until (listCount is 1)
set o's temp to {}
repeat with i from 2 to listCount by 2
set end of o's temp to (item (i - 1) of o's listCollector) & (item i of o's listCollector)
end repeat
if (listCount mod 2 is 1) then set item -1 of o's temp to (end of o's temp) & (end of o's listCollector)
set o's listCollector to o's temp
set o's temp to {}
set listCount to (count o's listCollector)
end repeat
-- Concatenate the result to the output list and prepare to go round again.
set o's output to o's output & (beginning of o's listCollector)
set sweepLength to sweepLength * sweepLength
set multiplier to multiplier * multiplier
end repeat
-- Lose the initial 0 and any ebans before the specified start number.
set resultCount to (count o's output)
if (resultCount is 1) then
set o's output to {}
else
repeat with i from 2 to resultCount
if (item i of o's output ≥ startNumber) then exit repeat
end repeat
set o's output to items i thru resultCount of o's output
end if
if (endNumber = limit) then set end of o's output to "(Limit of AppleScript's number precision.)"
return o's output
end getEbans
 
-- Task code:
Line 59 ⟶ 279:
set AppleScript's text item delimiters to ", "
set collectorebans to {}getEbans(0, 1000)
set end of output to ((count ebans) as text) & " eban numbers between 0 and 1,000:" & (linefeed & " " & ebans)
repeat with i from 0 to 1000
set ebans to getEbans(1000, 4000)
if (isEban(i) is true) then set end of collector to i
set end of output to ((count ebans) as text) & " between 1,000 and 4,000:" & (linefeed & " " & ebans)
end repeat
set end of output to ((count collectorgetEbans(0, 10000)) as text) & " ebanup numbersto betweenand 0 andincluding 110,000:" & linefeed & " " & collector
set end of output to ((count getEbans(0, 100000)) as text) & " up to and including 100,000"
set end of output to ((count getEbans(0, 1000000)) as text) & " up to and including 1,000,000"
set collector to {}
set end of output to ((count getEbans(0, 10000000)) as text) & " up to and including 10,000,000"
repeat with i from 1000 to 4000
set ebans to getEbans(6.606606602E+10, 1.0E+12)
if (isEban(i) is true) then set end of collector to i
set end of output to ((count ebans) as text) & " between 66,066,066,020 and 1,000,000,000,000:" & (linefeed & " " & ebans)
end repeat
set end of output to ((count collector) as text) & " eban numbers between 1,000 and 4,000:" & linefeed & " " & collector
set counter to 0
set landmarks to {10000, 100000, 1000000, 10000000}
repeat with i from 0 to 10000000
if (isEban(i) is true) then set counter to counter + 1
if (i mod 10000 is 0) then
repeat with j from 1 to 4
if (item j of landmarks is i) then
set end of output to (counter as text) & " eban numbers up to and including " & ¬
item j of {"10,000", "100,000", "1,000,000", "10,000,000"}
exit repeat
end if
end repeat
end if
end repeat
set AppleScript's text item delimiters to linefeed
Line 93 ⟶ 297:
end runTask
 
runTask()</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">"19 eban numbers between 0 and 1,000:
2, 4, 6, 30, 32, 34, 36, 40, 42, 44, 46, 50, 52, 54, 56, 60, 62, 64, 66
21 eban numbers between 1,000 and 4,000:
2000, 2002, 2004, 2006, 2030, 2032, 2034, 2036, 2040, 2042, 2044, 2046, 2050, 2052, 2054, 2056, 2060, 2062, 2064, 2066, 4000
79 eban numbers up to and including 10,000
399 eban numbers up to and including 100,000
399 eban numbers up to and including 1,000,000
1599 eban numbers up to and including 10,000,000"</lang>
16 between 66,066,066,020 and 1,000,000,000,000:
6.606606603E+10, 6.6066066032E+10, 6.6066066034E+10, 6.6066066036E+10, 6.606606604E+10, 6.6066066042E+10, 6.6066066044E+10, 6.6066066046E+10, 6.606606605E+10, 6.6066066052E+10, 6.6066066054E+10, 6.6066066056E+10, 6.606606606E+10, 6.6066066062E+10, 6.6066066064E+10, 6.6066066066E+10"</syntaxhighlight>
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">eban_numbers(min, max, show:=0){
counter := 0, output := ""
i := min
while ((i+=2) <= max)
{
b := floor(i / 1000000000)
r := Mod(i, 1000000000)
m := floor(r / 1000000)
r := Mod(i, 1000000)
t := floor(r / 1000)
r := Mod(r, 1000)
if (m >= 30 && m <= 66)
m := Mod(m, 10)
if (t >= 30 && t <= 66)
t := Mod(t, 10)
if (r >= 30 && r <= 66)
r := Mod(r, 10)
if (b = 0 || b = 2 || b = 4 || b = 6)
&& (m = 0 || m = 2 || m = 4 || m = 6)
&& (t = 0 || t = 2 || t = 4 || t = 6)
&& (r = 0 || r = 2 || r = 4 || r = 6)
counter++, (show ? output .= i " " : "")
}
return min "-" max " : " output " Count = " counter
}</syntaxhighlight>
Examples:<syntaxhighlight lang="autohotkey">MsgBox, 262144, , % eban_numbers(0, 1000, 1)
MsgBox, 262144, , % eban_numbers(1000, 4000, 1)
MsgBox, 262144, , % eban_numbers(0, 10000)
MsgBox, 262144, , % eban_numbers(0, 100000)
MsgBox, 262144, , % eban_numbers(0, 1000000)
MsgBox, 262144, , % eban_numbers(0, 100000000)</syntaxhighlight>
{{out}}
<pre>2-1000 : 2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66 Count = 19
1000-4000 : 2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000 Count = 21
2-10000 : Count = 79
2-100000 : Count = 399
2-1000000 : Count = 399
2-10000000 : Count = 1599
2-100000000 : Count = 7999</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f EBAN_NUMBERS.AWK
# converted from FreeBASIC
Line 143 ⟶ 390:
return(n == 0 || n == 2 || n == 4 || n == 6)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 157 ⟶ 404:
=={{header|C}}==
{{trans|D}}
<langsyntaxhighlight lang="c">#include "stdio.h"
#include "stdbool.h"
 
Line 220 ⟶ 467:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 249 ⟶ 496:
=={{header|C sharp|C#}}==
{{trans|D}}
<langsyntaxhighlight lang="csharp">using System;
 
namespace EbanNumbers {
Line 311 ⟶ 558:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 341 ⟶ 588:
=={{header|C++}}==
{{trans|D}}
<langsyntaxhighlight lang="cpp">#include <iostream>
 
struct Interval {
Line 396 ⟶ 643:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 423 ⟶ 670:
eban numbers up to and including 1000000000:
count = 7999</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">eban = cluster is numbers
rep = null
% Next valid E-ban number in the range [0..999]
next = proc (n: int) returns (int) signals (no_more)
if n>=66 then signal no_more end
if n<0 then return(0) end
% advance low digit (two four six)
if (n//10=0) then n := (n/10)*10 + 2
elseif (n//10=2) then n := (n/10)*10 + 4
elseif (n//10=4) then n := (n/10)*10 + 6
elseif (n//10=6) then n := (n/10)*10 + 10
end
% this might put us into tEn, twEnty which are invalid
if (n//100/10 = 1) then n := n + 20 % ten + 20 = 30
elseif (n//100/10 = 2) then n := n + 10 % twEnty + 10 = 30
end
return(n)
end next
% Yield all valid E_ban numbers
% (sextillion and upwards aren't handled)
numbers = iter () yields (int)
parts: array[int] := array[int]$[0: 2]
while true do
num: int := 0
for m: int in array[int]$indexes(parts) do
num := num + parts[m] * 1000 ** m
end
yield(num)
for m: int in array[int]$indexes(parts) do
begin
parts[m] := next(parts[m])
break
end except when no_more:
parts[m] := 0
end
end
if array[int]$top(parts) = 0 then
array[int]$addh(parts,2)
end
end
end numbers
end eban
 
start_up = proc ()
maxmagn = 1000000000000
po: stream := stream$primary_output()
 
count: int := 0
upto_1k: int := 0
between_1k_4k: int := 0
 
disp_1k: bool := false
disp_4k: bool := false
nextmagn: int := 10000
for i: int in eban$numbers() do
while i>nextmagn do
stream$putl(po, int$unparse(count)
|| " eban numbers <= "
|| int$unparse(nextmagn))
nextmagn := nextmagn * 10
end
count := count + 1
 
if i<1000 then upto_1k := upto_1k + 1
elseif i<=4000 then between_1k_4k := between_1k_4k + 1
end
if i>1000 & ~disp_1k then
disp_1k := true
stream$putl(po, "\n" || int$unparse(upto_1k)
|| " eban numbers <= 1000\n")
end
if i<=4000 then stream$putright(po, int$unparse(i), 5) end
if i>4000 & ~disp_4k then
disp_4k := true
stream$putl(po, "\n" || int$unparse(between_1k_4k)
|| " eban numbers 1000 <= x <= 4000\n")
end
if nextmagn>maxmagn then break end
end
end start_up </syntaxhighlight>
{{out}}
<pre> 2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
19 eban numbers <= 1000
 
2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000
21 eban numbers 1000 <= x <= 4000
 
79 eban numbers <= 10000
399 eban numbers <= 100000
399 eban numbers <= 1000000
1599 eban numbers <= 10000000
7999 eban numbers <= 100000000
7999 eban numbers <= 1000000000
31999 eban numbers <= 10000000000
159999 eban numbers <= 100000000000
159999 eban numbers <= 1000000000000</pre>
 
=={{header|D}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="d">import std.stdio;
 
struct Interval {
Line 479 ⟶ 838:
writeln;
}
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to an including 1000:
Line 506 ⟶ 865:
eban numbers up to an including 1000000000:
count = 7999</pre>
 
=={{header|EasyLang}}==
{{trans|AWK}}
<syntaxhighlight lang=easylang>
func x n .
if n = 0 or n = 2 or n = 4 or n = 6
return 1
.
.
proc go start stop printable . .
write start & " - " & stop & ":"
for i = start step 2 to stop
b = i div 1000000000
r = i mod 1000000000
m = r div 1000000
r = i mod 1000000
t = r div 1000
r = r mod 1000
if m >= 30 and m <= 66
m = m mod 10
.
if t >= 30 and t <= 66
t = t mod 10
.
if r >= 30 and r <= 66
r = r mod 10
.
if x b = 1 and x m = 1 and x t = 1 and x r = 1
count += 1
if printable = 1
write " " & i
.
.
.
print " (count=" & count & ")"
.
go 2 1000 1
go 1000 4000 1
go 2 10000 0
go 2 100000 0
go 2 1000000 0
go 2 10000000 0
go 2 100000000 0
</syntaxhighlight>
 
=={{header|Factor}}==
{{trans|Julia}}
<langsyntaxhighlight lang="factor">USING: arrays formatting fry io kernel math math.functions
math.order math.ranges prettyprint sequences ;
 
Line 523 ⟶ 926:
 
1 1000 1000 4000 [ .eban-range ] 2bi@
4 9 [a,b] [ [ 1 10 ] dip ^ .eban-count ] each</langsyntaxhighlight>
{{out}}
<pre>
Line 537 ⟶ 940:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
' Eban_numbers
' Un número eban es un número que no tiene la letra e cuando el número está escrito en inglés.
Line 596 ⟶ 999:
Print "Run time: " & (tiempo) & " seconds."
End
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 627 ⟶ 1,030:
=={{header|Fōrmulæ}}==
 
In [{{FormulaeEntry|page=https://wiki.formulae.org/?script=examples/Eban_numbers this] page you can see the solution of this task.}}
 
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text ([http://wiki.formulae.org/Editing_F%C5%8Drmul%C3%A6_expressions more info]). Moreover, there can be multiple visual representations of the same program. Even though it is possible to have textual representation &mdash;i.e. XML, JSON&mdash; they are intended for transportation effects more than visualization and edition.
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 695 ⟶ 1,094:
fmt.Println("count =", count, "\n")
}
}</langsyntaxhighlight>
 
{{out}}
Line 725 ⟶ 1,124:
count = 7999
</pre>
 
=={{header|Groovy}}==
{{trans|Java}}
<syntaxhighlight lang="groovy">class Main {
private static class Range {
int start
int end
boolean print
 
Range(int s, int e, boolean p) {
start = s
end = e
print = p
}
}
 
static void main(String[] args) {
List<Range> rgs = Arrays.asList(
new Range(2, 1000, true),
new Range(1000, 4000, true),
new Range(2, 10_000, false),
new Range(2, 100_000, false),
new Range(2, 1_000_000, false),
new Range(2, 10_000_000, false),
new Range(2, 100_000_000, false),
new Range(2, 1_000_000_000, false)
)
for (Range rg : rgs) {
if (rg.start == 2) {
println("eban numbers up to and including $rg.end")
} else {
println("eban numbers between $rg.start and $rg.end")
}
int count = 0
for (int i = rg.start; i <= rg.end; ++i) {
int b = (int) (i / 1_000_000_000)
int r = i % 1_000_000_000
int m = (int) (r / 1_000_000)
r = i % 1_000_000
int t = (int) (r / 1_000)
r %= 1_000
if (m >= 30 && m <= 66) m %= 10
if (t >= 30 && t <= 66) t %= 10
if (r >= 30 && r <= 66) r %= 10
if (b == 0 || b == 2 || b == 4 || b == 6) {
if (m == 0 || m == 2 || m == 4 || m == 6) {
if (t == 0 || t == 2 || t == 4 || t == 6) {
if (r == 0 || r == 2 || r == 4 || r == 6) {
if (rg.print) {
print("$i ")
}
count++
}
}
}
}
}
if (rg.print) {
println()
}
println("count = $count")
println()
}
}
}</syntaxhighlight>
{{out}}
<pre>Same as the Java entry</pre>
 
=={{header|Haskell}}==
{{trans|Julia}}
<langsyntaxhighlight lang="haskell">{-# LANGUAGE NumericUnderscores #-}
import Data.List (intercalate)
import Text.Printf (printf)
Line 759 ⟶ 1,226:
, 100_000_000
, 1_000_000_000 ]
r = ((,) <$> thousands . length <*> show) . filter isEban</langsyntaxhighlight>
{{out}}
<pre>
Line 777 ⟶ 1,244:
 
=={{header|J}}==
<syntaxhighlight lang="j">
<lang J>
Filter =: (#~`)(`:6)
 
Line 802 ⟶ 1,269:
1e6 399
1e7 1599
</syntaxhighlight>
</lang>
 
Alternatively we could construct a sequence of eban numbers sufficient to satisfy some limit and then filter out any which exceed our limit:
 
<syntaxhighlight lang=J>ebanseq=: {{ (#~ y>:])}.,@([+/~1000*])^:(6<.<.1000^.y)~(,0 2 4 6+/~10*0 3 4 5 6) }}
 
(,:&":~ #) ebanseq 1000
19
2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
(,:&":~ #) (#~ 1000<])ebanseq 4000
21
2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000
# ebanseq 1e4
79
# ebanseq 1e5
399
# ebanseq 1e6
399
# ebanseq 1e7
1599
# ebanseq 1e8
7999
# ebanseq 1e9
7999
# ebanseq 1e10
31999
# ebanseq 1e11
159999
# ebanseq 1e12
159999
# ebanseq 1e13
639999
# ebanseq 1e14
3199999
# ebanseq 1e15
3199999
# ebanseq 1e16
12799999
# ebanseq 1e17
63999999</syntaxhighlight>
 
=={{header|Java}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="java">import java.util.List;
 
public class Main {
Line 866 ⟶ 1,372:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000
Line 894 ⟶ 1,400:
count = 7999</pre>
 
=={{header|jq}}==
'''Adapted from Julia and Wren'''
{{works with|jq}}
'''Works with gojq, the Go implementation of jq''' (*)
 
(*) gojq's memory requirements are rather extravagent and may prevent
completion of the task beyond 1E+7; the output shown below was
obtained using the C implementation of jq.
<syntaxhighlight lang="jq"># quotient and remainder
def quotient($a; $b; f; g): f = (($a/$b)|floor) | g = $a % $b;
 
def tasks:
[2, 1000, true],
[1000, 4000, true],
(1e4, 1e5, 1e6, 1e7, 1e8 | [2, ., false]) ;
 
def task:
def update(f): if (f >= 30 and f <= 66) then f %= 10 else . end;
 
tasks as $rg
| if $rg[0] == 2
then "eban numbers up to and including \($rg[1]):"
else "eban numbers between \($rg[0]) and \($rg[1]) (inclusive):"
end,
( foreach (range( $rg[0]; 1 + $rg[1]; 2), null) as $i ( { count: 0 };
.emit = false
| if $i == null then .total = .count
else quotient($i; 1e9; .b; .r)
| quotient(.r; 1e6; .m; .r)
| quotient(.r; 1e3; .t; .r)
| update(.m) | update(.t) | update(.r)
| if all(.b, .m, .t, .r; IN(0, 2, 4, 6))
then .count += 1
| if ($rg[2]) then .emit=$i else . end
else .
end
end;
if .emit then .emit else empty end,
if .total then "count = \(.count)\n" else empty end) );
 
task</syntaxhighlight>
{{out}}
<pre>
eban numbers up to and including 1000:
2
4
6
30
32
34
36
40
42
44
46
50
52
54
56
60
62
64
66
count = 19
 
eban numbers between 1000 and 4000 (inclusive):
2000
2002
2004
2006
2030
2032
2034
2036
2040
2042
2044
2046
2050
2052
2054
2056
2060
2062
2064
2066
4000
count = 21
 
eban numbers up to and including 1E+4:
count = 79
 
eban numbers up to and including 1E+5:
count = 399
 
eban numbers up to and including 1E+6:
count = 399
 
eban numbers up to and including 1E+7:
count = 1599
 
eban numbers up to and including 1E+8:
count = 7999
</pre>
=={{header|Julia}}==
<syntaxhighlight lang="julia">
<lang Julia>
function iseban(n::Integer)
b, r = divrem(n, oftype(n, 10 ^ 9))
Line 916 ⟶ 1,526:
println("eban numbers up to and including 100000000: ", count(iseban, 1:100000000))
println("eban numbers up to and including 1000000000: ", count(iseban, 1:1000000000))
</syntaxhighlight>
</lang>
 
{{out}}
Line 929 ⟶ 1,539:
eban numbers up to and including 100000000: 7999
eban numbers up to and including 1000000000: 7999</pre>
 
=={{header|K}}==
{{works with|ngn/k}}
<syntaxhighlight lang=K>eban: {1_((x<)_,/(,/(2*!4)+/:10*0,3+!4)+/:1000*)/0}@_:
 
#eban 1000
19
#(1000>)_eban 4000
21
#eban 1e4
79
#eban 1e5
399
#eban 1e6
399
#eban 1e7
1599
#eban 1e8
7999
#eban 1e9
7999
#eban 1e10
31999
#eban 1e11
159999
#eban 1e12
159999
#eban 1e13
639999
#eban 1e14
3199999</syntaxhighlight>
 
=={{header|Kotlin}}==
{{trans|Go}}
<langsyntaxhighlight lang="scala">// Version 1.3.21
 
typealias Range = Triple<Int, Int, Boolean>
Line 979 ⟶ 1,620:
println("count = $count\n")
}
}</langsyntaxhighlight>
 
{{output}}
Line 988 ⟶ 1,629:
=={{header|Lua}}==
{{trans|lang}}
<langsyntaxhighlight lang="lua">function makeInterval(s,e,p)
return {start=s, end_=e, print_=p}
end
Line 1,040 ⟶ 1,681:
end
 
main()</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 1,064 ⟶ 1,705:
eban numbers up to and including 1000000000:
count = 7999</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">ClearAll[ZeroTwoFourSixQ, EbanNumbers]
ZeroTwoFourSixQ[n_Integer] := (n == 0 || n == 2 || n == 4 || n == 6)
EbanNumbers[min_, max_, show : (False | True)] :=
Module[{counter, output, i, b, r, t, m},
counter = 0;
output = "";
i = min;
While[(i += 2) <= max,
{b, r} = QuotientRemainder[i, 10^9];
{m, r} = QuotientRemainder[r, 10^6];
{t, r} = QuotientRemainder[r, 10^3];
If[30 <= m <= 66,
m = Mod[m, 10];
];
If[30 <= t <= 66,
t = Mod[t, 10];
];
If[30 <= r <= 66,
r = Mod[r, 10];
];
If[ZeroTwoFourSixQ[b] && ZeroTwoFourSixQ[m] && ZeroTwoFourSixQ[t] &&
ZeroTwoFourSixQ[r],
counter++;
If[show,
output = output <> ToString[i] <> " ";
]
]
];
Print[min, "-", max, ": ", output, " count = ", counter]
]
EbanNumbers[0, 1000, True]
EbanNumbers[1000, 4000, True]
EbanNumbers[0, 10^4, False]
EbanNumbers[0, 10^5, False]
EbanNumbers[0, 10^6, False]
EbanNumbers[0, 10^7, False]</syntaxhighlight>
{{out}}
<pre>0-1000: 2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66 count = 19
1000-4000: 2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000 count = 21
0-10000: count = 79
0-100000: count = 399
0-1000000: count = 399
0-10000000: count = 1599</pre>
 
=={{header|Nim}}==
===Exhaustive search===
{{trans|Julia}}
<langsyntaxhighlight lang="nim">import strformat
 
proc iseban(n: int): bool =
Line 1,121 ⟶ 1,808:
if iseban(i):
inc count
echo &"\nNumber of eban numbers up to and including {100000000:8}: {count:4}"</langsyntaxhighlight>
 
{{out}}
Line 1,138 ⟶ 1,825:
 
Number of eban numbers up to and including 10000000: 1599
</pre>
===Algorithmic computation===
{{trans|Phix}}
<syntaxhighlight lang="nim">import math, strutils, strformat
 
#---------------------------------------------------------------------------------------------------
 
func ebanCount(p10: Natural): Natural =
## Return the count of eban numbers 1..10^p10.
let
n = p10 - p10 div 3
p5 = n div 2
p4 = (n + 1) div 2
result = 5^p5 * 4^p4 - 1
 
#---------------------------------------------------------------------------------------------------
 
func eban(n: Natural): bool =
## Return true if n is an eban number (only fully tested to 10e9).
if n == 0: return false
var n = n
while n != 0:
let thou = n mod 1000
if thou div 100 != 0: return false
if thou div 10 notin {0, 3, 4, 5, 6}: return false
if thou mod 10 notin {0, 2, 4, 6}: return false
n = n div 1000
result = true
 
#———————————————————————————————————————————————————————————————————————————————————————————————————
 
var s: seq[Natural]
for i in 0..1000:
if eban(i): s.add(i)
echo fmt"Eban to 1000: {s.join("", "")} ({s.len} items)"
 
s.setLen(0)
for i in 1000..4000:
if eban(i): s.add(i)
echo fmt"Eban 1000..4000: {s.join("", "")} ({s.len} items)"
 
import times
let t0 = getTime()
for i in 0..21:
echo fmt"ebanCount(10^{i}): {ebanCount(i)}"
echo ""
echo fmt"Time: {getTime() - t0}"</syntaxhighlight>
 
{{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)
ebanCount(10^0): 0
ebanCount(10^1): 3
ebanCount(10^2): 19
ebanCount(10^3): 19
ebanCount(10^4): 79
ebanCount(10^5): 399
ebanCount(10^6): 399
ebanCount(10^7): 1599
ebanCount(10^8): 7999
ebanCount(10^9): 7999
ebanCount(10^10): 31999
ebanCount(10^11): 159999
ebanCount(10^12): 159999
ebanCount(10^13): 639999
ebanCount(10^14): 3199999
ebanCount(10^15): 3199999
ebanCount(10^16): 12799999
ebanCount(10^17): 63999999
ebanCount(10^18): 63999999
ebanCount(10^19): 255999999
ebanCount(10^20): 1279999999
ebanCount(10^21): 1279999999
 
Time: 189 microseconds and 491 nanoseconds</pre>
 
=={{header|Odin}}==
<syntaxhighlight lang="Go">
package eban_numbers
/* imports */
import "core:fmt"
/* globals */
Range :: struct {
start: i32,
end: i32,
print: bool,
}
printcounter: i32 = 0
/* main block */
main :: proc() {
rgs := [?]Range{
{2, 1000, true},
{1000, 4000, true},
{2, 1e4, false},
{2, 1e5, false},
{2, 1e6, false},
{2, 1e7, false},
{2, 1e8, false},
{2, 1e9, false},
}
for rg in rgs {
if rg.start == 2 {
fmt.printf("eban numbers up to and including %d:\n", rg.end)
} else {
fmt.printf("eban numbers between %d and %d (inclusive):\n", rg.start, rg.end)
}
count := i32(0)
for i := rg.start; i <= i32(rg.end); i += i32(2) {
b := i / 1000000000
r := i % 1000000000
m := r / 1000000
r = i % 1000000
t := r / 1000
r %= 1000
if m >= 30 && m <= 66 {
m %= 10
}
if t >= 30 && t <= 66 {
t %= 10
}
if r >= 30 && r <= 66 {
r %= 10
}
if b == 0 || b == 2 || b == 4 || b == 6 {
if m == 0 || m == 2 || m == 4 || m == 6 {
if t == 0 || t == 2 || t == 4 || t == 6 {
if r == 0 || r == 2 || r == 4 || r == 6 {
if rg.print {
fmt.printf("%d ", i)
}
count += 1
}
}
}
}
}
if rg.print {
fmt.println()
}
fmt.println("count =", count, "\n")
}
}
</syntaxhighlight>
{{out}}
<pre>
eban numbers up to and including 1000:
2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
count = 19
 
eban numbers between 1000 and 4000 (inclusive):
2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000
count = 21
 
eban numbers up to and including 10000:
count = 79
 
eban numbers up to and including 100000:
count = 399
 
eban numbers up to and including 1000000:
count = 399
 
eban numbers up to and including 10000000:
count = 1599
 
eban numbers up to and including 100000000:
count = 7999
 
eban numbers up to and including 1000000000:
count = 7999
</pre>
 
Line 1,143 ⟶ 2,000:
===Exhaustive search===
A couple of 'e'-specific optimizations keep the running time reasonable.
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 1,176 ⟶ 2,033:
my $n = + grep { $_ <= 10**$exp } @OK;
printf "Number of eban numbers and %10s: %d\n", comma(10**$exp), $n;
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 1,192 ⟶ 2,049:
Alternately, a partial translation of Raku. Does not need to actually generate the e-ban numbers to count them. Display counts up to 10**21.
 
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use bigint;
Line 1,267 ⟶ 2,124:
printf "Up to and including %23s: %s\n", lc(num2word(10**$exp)), comma($nu);
}
}</langsyntaxhighlight>
<pre>============= e-ban: =============
e-ban numbers up to 1000: 19
Line 1,300 ⟶ 2,157:
=={{header|Phix}}==
Why count when you can calculate?
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>function count_eban(integer p10)
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
-- returns the count of eban numbers 1..power(10,p10)
<span style="color: #008080;">function</span> <span style="color: #000000;">count_eban</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">p10</span><span style="color: #0000FF;">)</span>
integer n = p10-floor(p10/3),
<span style="color: #000080;font-style:italic;">-- returns the count of eban numbers 1..power(10,p10)</span>
p5 = floor(n/2),
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">p10</span><span style="color: #0000FF;">-</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p10</span><span style="color: #0000FF;">/</span><span style="color: #000000;">3</span><span style="color: #0000FF;">),</span>
p4 = floor((n+1)/2)
<span style="color: #000000;">p5</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">),</span>
return power(5,p5)*power(4,p4)-1
<span style="color: #000000;">p4</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">((</span><span style="color: #000000;">n</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #008080;">return</span> <span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p5</span><span style="color: #0000FF;">)*</span><span style="color: #7060A8;">power</span><span style="color: #0000FF;">(</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">p4</span><span style="color: #0000FF;">)-</span><span style="color: #000000;">1</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
function eban(integer n)
-- returns true if n is an eban number (only fully tested to 10e9)
<span style="color: #008080;">function</span> <span style="color: #000000;">eban</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
if n=0 then return false end if
<span style="color: #000080;font-style:italic;">-- returns true if n is an eban number (only fully tested to 10e9)</span>
while n do
<span style="color: #008080;">if</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">false</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
integer thou = remainder(n,1000)
<span style="color: #008080;">while</span> <span style="color: #000000;">n</span> <span style="color: #008080;">do</span>
if floor(thou/100)!=0 then return false end if
<span style="color: #004080;">integer</span> <span style="color: #000000;">thou</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">)</span>
if not find(floor(thou/10),{0,3,4,5,6}) then return false end if
<span style="color: #008080;">if</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">thou</span><span style="color: #0000FF;">/</span><span style="color: #000000;">100</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">false</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
if not find(remainder(thou,10),{0,2,4,6}) then return false end if
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">thou</span><span style="color: #0000FF;">/</span><span style="color: #000000;">10</span><span style="color: #0000FF;">),{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">})</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">false</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
n = floor(n/1000)
<span style="color: #008080;">if</span> <span style="color: #008080;">not</span> <span style="color: #7060A8;">find</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">thou</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">),{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">})</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">false</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end while
<span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">/</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">)</span>
return true
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
end function
<span style="color: #008080;">return</span> <span style="color: #004600;">true</span>
 
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
sequence s = {}
for i=0 to 1000 do
<span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
if eban(i) then s &= i end if
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #000000;">1000</span> <span style="color: #008080;">do</span>
end for
<span style="color: #008080;">if</span> <span style="color: #000000;">eban</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">))</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
printf(1,"eban to 1000 : %v (%d items)\n",{s,length(s)})
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
s = {}
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"eban to 1000 : %s\n\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"items"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">))})</span>
for i=1000 to 4000 do
<span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
if eban(i) then s &= i end if
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1000</span> <span style="color: #008080;">to</span> <span style="color: #000000;">4000</span> <span style="color: #008080;">do</span>
end for
<span style="color: #008080;">if</span> <span style="color: #000000;">eban</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">))</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
printf(1,"eban 1000..4000 : %v (%d items)\n\n",{s,length(s)})
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
 
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"eban 1000..4000 : %s\n\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"items"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">4</span><span style="color: #0000FF;">))})</span>
atom t0 = time()
for i=0 to 21 do
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span>
printf(1,"count_eban(10^%d) : %,d\n",{i,count_eban(i)})
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">to</span> <span style="color: #000000;">21</span> <span style="color: #008080;">do</span>
end for
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"count_eban(10^%d) : %,d\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">count_eban</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)})</span>
?elapsed(time()-t0)</lang>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)</span>
<!--</syntaxhighlight>-->
{{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)
eban 1000..4000 : 2000 2002 2004 2006 ... 2062 2064 2066 4000 (21 items)
 
count_eban(10^0) : 0
Line 1,364 ⟶ 2,225:
count_eban(10^20) : 1,279,999,999
count_eban(10^21) : 1,279,999,999
"0.0s"
</pre>
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de _eban? (N)
(let
(B (/ N 1000000000)
Line 1,424 ⟶ 2,285:
(prinl)
(prinl "eban numbers up to an including 10000000:")
(prinl "count: " (car (eban 10000000)))</langsyntaxhighlight>
{{out}}
<pre>
Line 1,449 ⟶ 2,310:
 
=={{header|Python}}==
<syntaxhighlight lang="python">
<lang Python>
# Use inflect
 
Line 1,574 ⟶ 2,435:
print(" ")
print("Run time in seconds: "+str(after - before))
</syntaxhighlight>
</lang>
 
Output:
Line 1,619 ⟶ 2,480:
Run time in seconds: 1134.289519125
</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ 20 /mod
4 /mod
[ table 0 2 4 6 ]
swap
[ table 0 30 40 50 60 ]
+
over 0 = iff nip done
swap recurse 1000 * + ] is n->eban ( n --> n )
 
[] 1
[ dup n->eban
dup 10000001 < while
swap dip join
1+ again ]
2drop
dup dup
say "eban numbers up to and including 1000:"
cr
findwith [ 1000 > ] [ ]
split drop dup echo cr
say "count: " size echo
cr cr
say "eban numbers between 1000 and 4000 (inclusive):"
cr
dup dup
findwith [ 999 > ] [ ]
split nip
dup
findwith [ 4001 > ] [ ]
split drop dup echo cr
say "count: " size echo
cr cr
say "number of eban numbers up to and including 10000: "
dup findwith [ 10001 > ] [ ]
echo
cr cr
say "number of eban numbers up to and including 100000: "
dup findwith [ 100001 > ] [ ]
echo
cr cr
say "number of eban numbers up to and including 1000000: "
dup findwith [ 1000001 > ] [ ]
echo
cr cr
say "number of eban numbers up to and including 10000000: "
findwith [ 10000001 > ] [ ]
echo</syntaxhighlight>
 
{{out}}
 
<pre>eban numbers up to and including 1000
[ 2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66 ]
count: 19
 
eban numbers between 1000 and 4000 (inclusive):
[ 2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000 ]
count: 21
 
number of eban numbers up to and including 10000: 79
 
number of eban numbers up to and including 100000: 399
 
number of eban numbers up to and including 1000000: 399
 
number of eban numbers up to and including 10000000: 1599</pre>
 
=={{header|Raku}}==
Line 1,642 ⟶ 2,571:
Considering numbers up to <strong>10<sup>21</sup></strong>, as the task directions suggest.
 
<syntaxhighlight lang="raku" perl6line>use Lingua::EN::Numbers;
 
sub nban ($seq, $n = 'e') { ($seq).map: { next if .&cardinal.contains(any($n.lc.comb)); $_ } }
Line 1,713 ⟶ 2,642:
printf "Up to and including %{$s}s: %s\n", cardinal(10**($c+1)), comma(@counts[$c]);
}
}</langsyntaxhighlight>
{{out}}
<pre>============= e-ban: =============
Line 1,814 ⟶ 2,743:
=={{header|REXX}}==
Programming note: &nbsp; REXX has no shortcuts for &nbsp; '''if''' &nbsp; statements, so the multiple &nbsp; '''if''' &nbsp; statements weren't combined into one.
<langsyntaxhighlight lang="rexx">/*REXX program to display eban numbers (those that don't have an "e" their English name)*/
numeric digits 20 /*support some gihugic numbers for pgm.*/
parse arg $ /*obtain optional arguments from the cL*/
Line 1,851 ⟶ 2,780:
if hun\==' ' then return 1 /*any hundrEd (not zero) has an "e". */
end /*k*/ /*A "period" is a group of 3 dec. digs */
return 0 /*in the number, grouped from the right*/</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 1,874 ⟶ 2,803:
1599 eban numbers found for: 1 -10000000
═════════════════════════════════════════════════════════════════════════════════════════════════════════
</pre>
 
=={{header|RPL}}==
{{trans|Julia}}
{{works with|HP|49}}
« '''IF''' DUP '''THEN'''
1000000000 IDIV2
1000000 IDIV2
1000 IDIV2
3 →LIST
« → x « 30 x ≤ x 66 ≤ AND x 10 MOD x IFTE » » MAP
+
« { 0 2 4 6 } SWAP POS » MAP ΠLIST
'''END'''
» » '<span style="color:blue">EBAN?</span>' STO
« { }
UNROT '''FOR''' j
'''IF''' j <span style="color:blue">EBAN?</span> '''THEN''' j + '''END'''
'''NEXT'''
» » '<span style="color:blue">TASK1</span>' STO
« 0
1 ROT '''FOR''' j
'''IF''' j <span style="color:blue">EBAN?</span> '''THEN''' 1 + '''END'''
'''NEXT'''
» » '<span style="color:blue">TASK2</span>' STO
 
1 1000 <span style="color:blue">TASK1</span>
1000 4000 <span style="color:blue">TASK1</span>
10000 <span style="color:blue">TASK2</span>
{{out}}
<pre>
3: { 2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66 }
2: { 2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000 }
1: 79
</pre>
 
=={{header|Ruby}}==
{{trans|C#}}
<langsyntaxhighlight lang="ruby">def main
intervals = [
[2, 1000, true],
Line 1,934 ⟶ 2,899:
end
 
main()</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 1,964 ⟶ 2,929:
=={{header|Scala}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">object EbanNumbers {
 
class ERange(s: Int, e: Int, p: Boolean) {
Line 2,027 ⟶ 2,992:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to an including 1000
Line 2,056 ⟶ 3,021:
 
=={{header|Tailspin}}==
<langsyntaxhighlight lang="tailspin">
templates isEban
def number: $;
'$;' -> \(<'([246]|[3456][0246])(0[03456][0246])*'> $ !\) -> $number !
end isEban
</syntaxhighlight>
</lang>
 
Alternatively, if regex is not your thing, we can do it numerically, which actually runs faster
<langsyntaxhighlight lang="tailspin">
templates isEban
def number: $;
Line 2,071 ⟶ 3,036:
when <?($ mod 1000 <=0|=2|=4|=6|30..66?($ mod 10 <=0|=2|=4|=6>)>)> do $ ~/ 1000 -> #
end isEban
</syntaxhighlight>
</lang>
 
Either version is called by the following code
<langsyntaxhighlight lang="tailspin">
def small: [1..1000 -> isEban];
$small -> !OUT::write
Line 2,104 ⟶ 3,069:
 
' -> !OUT::write
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,126 ⟶ 3,091:
</pre>
 
=={{header|uBasic/4tH}}==
{{trans|Yabasic}}
<syntaxhighlight lang="qbasic">Push 2, 10^7, 0
Push 2, 10^6, 0
Push 2, 10^5, 0
Push 2, 10^4, 0
Push 1000, 4000, 1
Push 2, 1000, 1
 
z = XOR(NOT(0), 6)
 
Do While Used()
p = Pop() : e = Pop() : s = Pop()
 
If s = 2 Then
Print "eban numbers up to and including ";e
Else
Print "eban numbers between ";s;" and ";e;" (inclusive):"
EndIf
 
c = 0
For i = s To e Step 2
b = i / 1000000000
m = (i % 1000000000) / 1000000
r = i % 1000000
t = r / 1000
r = r % 1000
If ((m < 30) = 0) * ((m > 66) = 0) Then m = m % 10
If ((t < 30) = 0) * ((t > 66) = 0) Then t = t % 10
If ((r < 30) = 0) * ((r > 66) = 0) Then r = r % 10
If (AND(b, z) = 0) * (AND(m, z) = 0) * (AND(t, z) = 0) * (AND(r, z) = 0) Then
If p Then Print i;" "; : Fi
c = c + 1
EndIf
Next
If p Then Print
Print "count = ";c : Print
Loop</syntaxhighlight >
=={{header|Visual Basic .NET}}==
{{trans|D}}
<langsyntaxhighlight lang="vbnet">Module Module1
 
Structure Interval
Line 2,198 ⟶ 3,203:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>eban numbers up to and including 1000:
Line 2,225 ⟶ 3,230:
eban numbers up to and including 1000000000:
count = 7999</pre>
 
=={{header|V (Vlang)}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">
struct Range {
start i64
end i64
print bool
}
fn main() {
rgs := [
Range{2, 1000, true},
Range{1000, 4000, true},
Range{2, 10000, false},
Range{2, 100000, false},
Range{2, 1000000, false},
Range{2, 10000000, false},
Range{2, 100000000, false},
Range{2, 1000000000, false}
]
for rg in rgs {
if rg.start == 2 {
println("eban numbers up to and including $rg.end:")
} else {
println("eban numbers between $rg.start and $rg.end (inclusive):")
}
mut count := 0
for i := rg.start; i <= rg.end; i += 2 {
b := i / 1000000000
mut r := i % 1000000000
mut m := r / 1000000
r = i % 1000000
mut t := r / 1000
r %= 1000
if m >= 30 && m <= 66 {
m %= 10
}
if t >= 30 && t <= 66 {
t %= 10
}
if r >= 30 && r <= 66 {
r %= 10
}
if b == 0 || b == 2 || b == 4 || b == 6 {
if m == 0 || m == 2 || m == 4 || m == 6 {
if t == 0 || t == 2 || t == 4 || t == 6 {
if r == 0 || r == 2 || r == 4 || r == 6 {
if rg.print {
print("$i ")
}
count++
}
}
}
}
}
if rg.print {
println('')
}
println("count = $count\n")
}
}</syntaxhighlight>
 
{{out}}
<pre>
eban numbers up to and including 1000:
2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
count = 19
 
eban numbers between 1000 and 4000 (inclusive):
2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000
count = 21
 
eban numbers up to and including 10000:
count = 79
 
eban numbers up to and including 100000:
count = 399
 
eban numbers up to and including 1000000:
count = 399
 
eban numbers up to and including 10000000:
count = 1599
 
eban numbers up to and including 100000000:
count = 7999
 
eban numbers up to and including 1000000000:
count = 7999
</pre>
 
=={{header|Wren}}==
{{trans|Go}}
<langsyntaxhighlight ecmascriptlang="wren">var rgs = [
[2, 1000, true],
[1000, 4000, true],
Line 2,270 ⟶ 3,367:
if (rg[2]) System.print()
System.print("count = %(count)\n")
}</langsyntaxhighlight>
 
{{out}}
Line 2,297 ⟶ 3,394:
count = 7999
 
eban numbers up to and including 1000000000
count = 7999
</pre>
 
=={{header|XPL0}}==
{{trans|Wren}}
<syntaxhighlight lang "XPL0">include xpllib; \for Print
 
int Rgs, Rg, Count, I, B, R, M, T;
[Rgs:= [
[2, 1000, true],
[1000, 4000, true],
[2, 10000, false],
[2, 100000, false],
[2, 1000000, false],
[2, 10000000, false],
[2, 100000000, false],
[2, 1000000000, false] ];
for Rg:= 0 to 8-1 do
[if Rgs(Rg,0) = 2 then
Print("eban numbers up to and including %d\n", Rgs(Rg,1))
else
Print("eban numbers between %d and %d (inclusive):\n", Rgs(Rg,0), Rgs(Rg,1));
Count:= 0;
I:= Rgs(Rg,0);
while I <= Rgs(Rg,1) do
[B:= (I/1_000_000_000);
M:= rem(0) / 1_000_000;
T:= rem(0) / 1_000;
R:= rem(0);
if M >= 30 and M <= 66 then M:= rem(M/10);
if T >= 30 and T <= 66 then T:= rem(T/10);
if R >= 30 and R <= 66 then R:= rem(R/10);
if B = 0 or B = 2 or B = 4 or B = 6 then
if M = 0 or M = 2 or M = 4 or M = 6 then
if T = 0 or T = 2 or T = 4 or T = 6 then
if R = 0 or R = 2 or R = 4 or R = 6 then
[if Rgs(Rg,2) then Print("%d ", I);
Count:= Count+1;
];
I:= I+2;
];
if Rgs(Rg,2) then CrLf(0);
Print("count = %d\n", Count);
];
]</syntaxhighlight>
{{out}}
<pre>
eban numbers up to and including 1000
2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66
count = 19
eban numbers between 1000 and 4000 (inclusive):
2000 2002 2004 2006 2030 2032 2034 2036 2040 2042 2044 2046 2050 2052 2054 2056 2060 2062 2064 2066 4000
count = 21
eban numbers up to and including 10000
count = 79
eban numbers up to and including 100000
count = 399
eban numbers up to and including 1000000
count = 399
eban numbers up to and including 10000000
count = 1599
eban numbers up to and including 100000000
count = 7999
eban numbers up to and including 1000000000
count = 7999
Line 2,303 ⟶ 3,464:
=={{header|Yabasic}}==
{{trans|Go}}
<langsyntaxhighlight Yabasiclang="yabasic">data 2, 100, true
data 1000, 4000, true
data 2, 1e4, false
Line 2,346 ⟶ 3,507:
if printable Print
Print "count = ", count, "\n"
loop</langsyntaxhighlight>
 
=={{header|zkl}}==
{{trans|Go}}
<langsyntaxhighlight lang="zkl">rgs:=T( T(2, 1_000, True), // (start,end,print)
T(1_000, 4_000, True),
T(2, 1e4, False), T(2, 1e5, False), T(2, 1e6, False), T(2, 1e7, False),
Line 2,377 ⟶ 3,538:
println("count = %,d\n".fmt(count));
}
fcn magic(z){ z.isEven and z<=6 }</langsyntaxhighlight>
{{out}}
<pre style="height:35ex">
3,021

edits