Eban numbers: Difference between revisions

→‎{{header|ALGOL 68}}: Removed unnecessary test
m (→‎{{header|K}}: slightly simpler)
(→‎{{header|ALGOL 68}}: Removed unnecessary test)
 
(11 intermediate revisions by 8 users not shown)
Line 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 768 ⟶ 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 889 ⟶ 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,405 ⟶ 1,542:
=={{header|K}}==
{{works with|ngn/k}}
<syntaxhighlight lang=K>eban: 1_{{1_((y+1x<)>)#_,/x+/:1000*,/z}[(,/(2*!4)+/:10*0,3+!4;x])+/:1000*)/0}@_:
 
#eban 1000
19
#{x[&(1000<x]}eban>)_eban 4000
21
#eban 1e4
Line 1,689 ⟶ 1,826:
Number of eban numbers up to and including 10000000: 1599
</pre>
 
===Algorithmic computation===
{{trans|Phix}}
Line 1,764 ⟶ 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,571 ⟶ 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,823 ⟶ 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 3,017 ⟶ 3,325:
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="ecmascriptwren">var rgs = [
[2, 1000, true],
[1000, 4000, true],
3,026

edits