Eban numbers: Difference between revisions

→‎{{header|ALGOL 68}}: Removed unnecessary test
(→‎{{header|ALGOL 68}}: Removed unnecessary test)
 
(19 intermediate revisions by 11 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>
 
Line 81 ⟶ 82:
 
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>
 
Line 767 ⟶ 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}}==
Line 888 ⟶ 1,030:
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Eban_numbers}}
Fōrmulæ programs are not textual, visualization/edition of programs is done showing/manipulating structures but not text. 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 storage and transfer purposes more than visualization and edition.
 
Programs in Fōrmulæ are created/edited online in its [https://formulae.org website], However they run on execution servers. By default remote servers are used, but they are limited in memory and processing power, since they are intended for demonstration and casual use. A local server can be downloaded and installed, it has no limitations (it runs in your own computer). Because of that, example programs can be fully visualized and edited, but some of them will not run if they require a moderate or heavy computation/memory resources, and no local server is being used.
 
In '''[https://formulae.org/?example=Eban_numbers this]''' page you can see the program(s) related to this task and their results.
 
=={{header|Go}}==
Line 1,132 ⟶ 1,270:
1e7 1599
</syntaxhighlight>
 
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}}==
Line 1,362 ⟶ 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}}==
Line 1,618 ⟶ 1,826:
Number of eban numbers up to and including 10000000: 1599
</pre>
 
===Algorithmic computation===
{{trans|Phix}}
Line 1,693 ⟶ 1,900:
 
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>
 
=={{header|Perl}}==
Line 2,177 ⟶ 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 2,432 ⟶ 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>
 
Line 2,684 ⟶ 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}}
Line 2,784 ⟶ 3,231:
count = 7999</pre>
 
=={{header|V (Vlang)}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">
struct Range {
start i64
Line 2,878 ⟶ 3,325:
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="ecmascriptwren">var rgs = [
[2, 1000, true],
[1000, 4000, true],
Line 2,947 ⟶ 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
3,021

edits