Eban numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Simplify, fix problem with irregulars (didn't affect e-bans as all irregulars contain an e)) |
|||
Line 33: | Line 33: | ||
:* The OEIS entry: [http://oeis.org/A006933 A6933, eban numbers]. |
:* The OEIS entry: [http://oeis.org/A006933 A6933, eban numbers]. |
||
<br><br> |
<br><br> |
||
=={{header|D}}== |
|||
{{trans|Kotlin}} |
|||
<lang d>import std.stdio; |
|||
struct Interval { |
|||
int start, end; |
|||
bool print; |
|||
} |
|||
void main() { |
|||
Interval[] intervals = [ |
|||
{2, 1_000, true}, |
|||
{1_000, 4_000, true}, |
|||
{2, 10_000, false}, |
|||
{2, 100_000, false}, |
|||
{2, 1_000_000, false}, |
|||
{2, 10_000_000, false}, |
|||
{2, 100_000_000, false}, |
|||
{2, 1_000_000_000, false}, |
|||
]; |
|||
foreach (intv; intervals) { |
|||
if (intv.start == 2) { |
|||
writeln("eban numbers up to an including ", intv.end, ':'); |
|||
} else { |
|||
writeln("eban numbers between ", intv.start ," and ", intv.end, " (inclusive):"); |
|||
} |
|||
int count; |
|||
for (int i = intv.start; i <= intv.end; i = i + 2) { |
|||
int b = i / 1_000_000_000; |
|||
int r = i % 1_000_000_000; |
|||
int m = r / 1_000_000; |
|||
r = i % 1_000_000; |
|||
int t = 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 (intv.print) write(i, ' '); |
|||
count++; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
if (intv.print) { |
|||
writeln(); |
|||
} |
|||
writeln("count = ", count); |
|||
writeln; |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>eban numbers up to an 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 an including 10000: |
|||
count = 79 |
|||
eban numbers up to an including 100000: |
|||
count = 399 |
|||
eban numbers up to an including 1000000: |
|||
count = 399 |
|||
eban numbers up to an including 10000000: |
|||
count = 1599 |
|||
eban numbers up to an including 100000000: |
|||
count = 7999 |
|||
eban numbers up to an including 1000000000: |
|||
count = 7999</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |