Eban numbers: Difference between revisions

→‎{{header|ALGOL 68}}: Removed unnecessary test
(Added Easylang)
(→‎{{header|ALGOL 68}}: Removed unnecessary test)
 
(5 intermediate revisions by 4 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 2,706 ⟶ 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,958 ⟶ 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,152 ⟶ 3,325:
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="ecmascriptwren">var rgs = [
[2, 1000, true],
[1000, 4000, true],
3,028

edits