Eban numbers: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 83:
2-100000000: (count=7999)
</pre>
 
=={{header|C}}==
{{trans|D}}
Line 175 ⟶ 176:
count = 7999</pre>
 
=={{header|C++ sharp|C#}}==
{{trans|D}}
<lang cpp>#include <iostream>
 
struct Interval {
int start, end;
bool print;
};
 
int main() {
Interval intervals[] = {
{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 (auto intv : intervals) {
if (intv.start == 2) {
std::cout << "eban numbers up to and including " << intv.end << ":\n";
} else {
std::cout << "eban numbers bwteen " << intv.start << " and " << intv.end << " (inclusive):\n";
}
 
int count = 0;
for (int i = intv.start; i <= intv.end; i += 2) {
int b = i / 1000000000;
int r = i % 1000000000;
int m = r / 1000000;
r = i % 1000000;
int 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 (intv.print) std::cout << i << ' ';
count++;
}
}
}
}
}
if (intv.print) {
std::cout << '\n';
}
std::cout << "count = " << count << "\n\n";
}
 
return 0;
}</lang>
{{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 bwteen 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|C#|C sharp}}==
{{trans|D}}
<lang csharp>using System;
Line 331 ⟶ 247:
 
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|C++}}==
{{trans|D}}
<lang cpp>#include <iostream>
 
struct Interval {
int start, end;
bool print;
};
 
int main() {
Interval intervals[] = {
{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 (auto intv : intervals) {
if (intv.start == 2) {
std::cout << "eban numbers up to and including " << intv.end << ":\n";
} else {
std::cout << "eban numbers bwteen " << intv.start << " and " << intv.end << " (inclusive):\n";
}
 
int count = 0;
for (int i = intv.start; i <= intv.end; i += 2) {
int b = i / 1000000000;
int r = i % 1000000000;
int m = r / 1000000;
r = i % 1000000;
int 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 (intv.print) std::cout << i << ' ';
count++;
}
}
}
}
}
if (intv.print) {
std::cout << '\n';
}
std::cout << "count = " << count << "\n\n";
}
 
return 0;
}</lang>
{{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 bwteen 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
Line 1,096 ⟶ 1,097:
Up to and including one hundred quintillion: 1,279,999,999
Up to and including one sextillion: 1,279,999,999</pre>
 
=={{header|Perl 6}}==
{{works with|Rakudo|2018.12}}
Modular approach, very little is hard coded. Change the $upto order-of-magnitude limit to adjust the search/display ranges. Change the letter(s) given to the enumerate / count subs to modify which letter(s) to disallow.
 
Will handle multi-character 'bans'. Demonstrate for e-ban, t-ban and subur-ban.
 
Directly find :
:* [[oeis:A006933|OEIS:A006933 Numbers without e]]: Eban
:* [[oeis:A008521|OEIS:A008521 Numbers without o]]: Oban
:* [[oeis:A008523|OEIS:A008523 Numbers without t]]: Tban
:* [[oeis:A072954|OEIS:A072954 Numbers without a, i, l, t]]: TALIban
:* [[oeis:A072955|OEIS:A072955 Numbers without b, r, s, u]]: SUBURban
:* [[oeis:A072956|OEIS:A072956 Numbers without r, t, u]]: TURban
:* [[oeis:A072957|OEIS:A072957 Numbers without r, u]]: URban
:* [[oeis:A072958|OEIS:A072958 Numbers without a, c, i, l]]: CALIban
:* [[oeis:A089589|OEIS:A089589 Numbers without i]]: Iban
:* [[oeis:A089590|OEIS:A089590 Numbers without u]]: Uban
:* ''and so on...''
 
Considering numbers up to <strong>10<sup>21</sup></strong>, as the task directions suggest.
 
<lang perl6>use Lingua::EN::Numbers;
 
sub nban ($seq, $n = 'e') { ($seq).map: { next if .&cardinal.contains(any($n.lc.comb)); $_ } }
 
sub enumerate ($n, $upto) {
my @ban = [nban(1 .. 99, $n)],;
my @orders;
(2 .. $upto).map: -> $o {
given $o % 3 { # Compensate for irregulars: 11 - 19
when 1 { @orders.push: [flat (10**($o - 1) X* 10 .. 19).map(*.&nban($n)), |(10**$o X* 2 .. 9).map: *.&nban($n)] }
default { @orders.push: [flat (10**$o X* 1 .. 9).map: *.&nban($n)] }
}
}
^@orders .map: -> $o {
@ban.push: [] and next unless +@orders[$o];
my @these;
@orders[$o].map: -> $m {
@these.push: $m;
for ^@ban -> $b {
next unless +@ban[$b];
@these.push: $_ for (flat @ban[$b]) »+» $m ;
}
}
@ban.push: @these;
}
@ban.unshift(0) if nban(0, $n);
flat @ban.map: *.flat;
}
 
sub count ($n, $upto) {
my @orders;
(2 .. $upto).map: -> $o {
given $o % 3 { # Compensate for irregulars: 11 - 19
when 1 { @orders.push: [flat (10**($o - 1) X* 10 .. 19).map(*.&nban($n)), |(10**$o X* 2 .. 9).map: *.&nban($n)] }
default { @orders.push: [flat (10**$o X* 1 .. 9).map: *.&nban($n)] }
}
}
my @count = +nban(1 .. 99, $n);
^@orders .map: -> $o {
@count.push: 0 and next unless +@orders[$o];
my $prev = so (@orders[$o].first( { $_ ~~ /^ '1' '0'+ $/ } ) // 0 );
my $sum = @count.sum;
my $these = +@orders[$o] * $sum + @orders[$o];
$these-- if $prev;
@count[1 + $o] += $these;
++@count[$o] if $prev;
}
++@count[0] if nban(0, $n);
[\+] @count;
}
 
#for < e o t tali subur tur ur cali i u > -> $n { # All of them
for < e t subur > -> $n { # An assortment for demonstration
my $upto = 21; # 1e21
my @bans = enumerate($n, 4);
my @counts = count($n, $upto);
 
# DISPLAY
my @k = @bans.grep: * < 1000;
my @j = @bans.grep: 1000 <= * <= 4000;
put "\n============= {$n}-ban: =============\n" ~
"{$n}-ban numbers up to 1000: {+@k}\n[{@k».&comma}]\n\n" ~
"{$n}-ban numbers between 1,000 & 4,000: {+@j}\n[{@j».&comma}]\n" ~
"\nCounts of {$n}-ban numbers up to {cardinal 10**$upto}"
;
 
my $s = max (1..$upto).map: { (10**$_).&cardinal.chars };
@counts.unshift: @bans.first: * > 10, :k;
for ^$upto -> $c {
printf "Up to and including %{$s}s: %s\n", cardinal(10**($c+1)), comma(@counts[$c]);
}
}</lang>
{{out}}
<pre>============= e-ban: =============
e-ban numbers up to 1000: 19
[2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66]
 
e-ban numbers between 1,000 & 4,000: 21
[2,000 2,002 2,004 2,006 2,030 2,032 2,034 2,036 2,040 2,042 2,044 2,046 2,050 2,052 2,054 2,056 2,060 2,062 2,064 2,066 4,000]
 
Counts of e-ban numbers up to one sextillion
Up to and including ten: 3
Up to and including one hundred: 19
Up to and including one thousand: 19
Up to and including ten thousand: 79
Up to and including one hundred thousand: 399
Up to and including one million: 399
Up to and including ten million: 1,599
Up to and including one hundred million: 7,999
Up to and including one billion: 7,999
Up to and including ten billion: 31,999
Up to and including one hundred billion: 159,999
Up to and including one trillion: 159,999
Up to and including ten trillion: 639,999
Up to and including one hundred trillion: 3,199,999
Up to and including one quadrillion: 3,199,999
Up to and including ten quadrillion: 12,799,999
Up to and including one hundred quadrillion: 63,999,999
Up to and including one quintillion: 63,999,999
Up to and including ten quintillion: 255,999,999
Up to and including one hundred quintillion: 1,279,999,999
Up to and including one sextillion: 1,279,999,999
 
============= t-ban: =============
t-ban numbers up to 1000: 56
[0 1 4 5 6 7 9 11 100 101 104 105 106 107 109 111 400 401 404 405 406 407 409 411 500 501 504 505 506 507 509 511 600 601 604 605 606 607 609 611 700 701 704 705 706 707 709 711 900 901 904 905 906 907 909 911]
 
t-ban numbers between 1,000 & 4,000: 0
[]
 
Counts of t-ban numbers up to one sextillion
Up to and including ten: 7
Up to and including one hundred: 9
Up to and including one thousand: 56
Up to and including ten thousand: 56
Up to and including one hundred thousand: 56
Up to and including one million: 57
Up to and including ten million: 392
Up to and including one hundred million: 785
Up to and including one billion: 5,489
Up to and including ten billion: 38,416
Up to and including one hundred billion: 76,833
Up to and including one trillion: 537,824
Up to and including ten trillion: 537,824
Up to and including one hundred trillion: 537,824
Up to and including one quadrillion: 537,825
Up to and including ten quadrillion: 3,764,768
Up to and including one hundred quadrillion: 7,529,537
Up to and including one quintillion: 52,706,752
Up to and including ten quintillion: 52,706,752
Up to and including one hundred quintillion: 52,706,752
Up to and including one sextillion: 52,706,752
 
============= subur-ban: =============
subur-ban numbers up to 1000: 35
[1 2 5 8 9 10 11 12 15 18 19 20 21 22 25 28 29 50 51 52 55 58 59 80 81 82 85 88 89 90 91 92 95 98 99]
 
subur-ban numbers between 1,000 & 4,000: 0
[]
 
Counts of subur-ban numbers up to one sextillion
Up to and including ten: 6
Up to and including one hundred: 35
Up to and including one thousand: 35
Up to and including ten thousand: 35
Up to and including one hundred thousand: 35
Up to and including one million: 36
Up to and including ten million: 216
Up to and including one hundred million: 2,375
Up to and including one billion: 2,375
Up to and including ten billion: 2,375
Up to and including one hundred billion: 2,375
Up to and including one trillion: 2,375
Up to and including ten trillion: 2,375
Up to and including one hundred trillion: 2,375
Up to and including one quadrillion: 2,375
Up to and including ten quadrillion: 2,375
Up to and including one hundred quadrillion: 2,375
Up to and including one quintillion: 2,375
Up to and including ten quintillion: 2,375
Up to and including one hundred quintillion: 2,375
Up to and including one sextillion: 2,375</pre>
 
Note that the limit to one sextillion is somewhat arbitrary and is just to match the task parameters.
 
This will quite happily count *-bans up to one hundred centillion. (10<sup>305</sup>) It takes longer, but still on the order of seconds, not minutes.
<pre>Counts of e-ban numbers up to one hundred centillion
...
Up to and including one hundred centillion: 35,184,372,088,831,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999</pre>
 
=={{header|Phix}}==
Line 1,609 ⟶ 1,419:
Run time in seconds: 1134.289519125
</pre>
 
=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.12}}
Modular approach, very little is hard coded. Change the $upto order-of-magnitude limit to adjust the search/display ranges. Change the letter(s) given to the enumerate / count subs to modify which letter(s) to disallow.
 
Will handle multi-character 'bans'. Demonstrate for e-ban, t-ban and subur-ban.
 
Directly find :
:* [[oeis:A006933|OEIS:A006933 Numbers without e]]: Eban
:* [[oeis:A008521|OEIS:A008521 Numbers without o]]: Oban
:* [[oeis:A008523|OEIS:A008523 Numbers without t]]: Tban
:* [[oeis:A072954|OEIS:A072954 Numbers without a, i, l, t]]: TALIban
:* [[oeis:A072955|OEIS:A072955 Numbers without b, r, s, u]]: SUBURban
:* [[oeis:A072956|OEIS:A072956 Numbers without r, t, u]]: TURban
:* [[oeis:A072957|OEIS:A072957 Numbers without r, u]]: URban
:* [[oeis:A072958|OEIS:A072958 Numbers without a, c, i, l]]: CALIban
:* [[oeis:A089589|OEIS:A089589 Numbers without i]]: Iban
:* [[oeis:A089590|OEIS:A089590 Numbers without u]]: Uban
:* ''and so on...''
 
Considering numbers up to <strong>10<sup>21</sup></strong>, as the task directions suggest.
 
<lang perl6>use Lingua::EN::Numbers;
 
sub nban ($seq, $n = 'e') { ($seq).map: { next if .&cardinal.contains(any($n.lc.comb)); $_ } }
 
sub enumerate ($n, $upto) {
my @ban = [nban(1 .. 99, $n)],;
my @orders;
(2 .. $upto).map: -> $o {
given $o % 3 { # Compensate for irregulars: 11 - 19
when 1 { @orders.push: [flat (10**($o - 1) X* 10 .. 19).map(*.&nban($n)), |(10**$o X* 2 .. 9).map: *.&nban($n)] }
default { @orders.push: [flat (10**$o X* 1 .. 9).map: *.&nban($n)] }
}
}
^@orders .map: -> $o {
@ban.push: [] and next unless +@orders[$o];
my @these;
@orders[$o].map: -> $m {
@these.push: $m;
for ^@ban -> $b {
next unless +@ban[$b];
@these.push: $_ for (flat @ban[$b]) »+» $m ;
}
}
@ban.push: @these;
}
@ban.unshift(0) if nban(0, $n);
flat @ban.map: *.flat;
}
 
sub count ($n, $upto) {
my @orders;
(2 .. $upto).map: -> $o {
given $o % 3 { # Compensate for irregulars: 11 - 19
when 1 { @orders.push: [flat (10**($o - 1) X* 10 .. 19).map(*.&nban($n)), |(10**$o X* 2 .. 9).map: *.&nban($n)] }
default { @orders.push: [flat (10**$o X* 1 .. 9).map: *.&nban($n)] }
}
}
my @count = +nban(1 .. 99, $n);
^@orders .map: -> $o {
@count.push: 0 and next unless +@orders[$o];
my $prev = so (@orders[$o].first( { $_ ~~ /^ '1' '0'+ $/ } ) // 0 );
my $sum = @count.sum;
my $these = +@orders[$o] * $sum + @orders[$o];
$these-- if $prev;
@count[1 + $o] += $these;
++@count[$o] if $prev;
}
++@count[0] if nban(0, $n);
[\+] @count;
}
 
#for < e o t tali subur tur ur cali i u > -> $n { # All of them
for < e t subur > -> $n { # An assortment for demonstration
my $upto = 21; # 1e21
my @bans = enumerate($n, 4);
my @counts = count($n, $upto);
 
# DISPLAY
my @k = @bans.grep: * < 1000;
my @j = @bans.grep: 1000 <= * <= 4000;
put "\n============= {$n}-ban: =============\n" ~
"{$n}-ban numbers up to 1000: {+@k}\n[{@k».&comma}]\n\n" ~
"{$n}-ban numbers between 1,000 & 4,000: {+@j}\n[{@j».&comma}]\n" ~
"\nCounts of {$n}-ban numbers up to {cardinal 10**$upto}"
;
 
my $s = max (1..$upto).map: { (10**$_).&cardinal.chars };
@counts.unshift: @bans.first: * > 10, :k;
for ^$upto -> $c {
printf "Up to and including %{$s}s: %s\n", cardinal(10**($c+1)), comma(@counts[$c]);
}
}</lang>
{{out}}
<pre>============= e-ban: =============
e-ban numbers up to 1000: 19
[2 4 6 30 32 34 36 40 42 44 46 50 52 54 56 60 62 64 66]
 
e-ban numbers between 1,000 & 4,000: 21
[2,000 2,002 2,004 2,006 2,030 2,032 2,034 2,036 2,040 2,042 2,044 2,046 2,050 2,052 2,054 2,056 2,060 2,062 2,064 2,066 4,000]
 
Counts of e-ban numbers up to one sextillion
Up to and including ten: 3
Up to and including one hundred: 19
Up to and including one thousand: 19
Up to and including ten thousand: 79
Up to and including one hundred thousand: 399
Up to and including one million: 399
Up to and including ten million: 1,599
Up to and including one hundred million: 7,999
Up to and including one billion: 7,999
Up to and including ten billion: 31,999
Up to and including one hundred billion: 159,999
Up to and including one trillion: 159,999
Up to and including ten trillion: 639,999
Up to and including one hundred trillion: 3,199,999
Up to and including one quadrillion: 3,199,999
Up to and including ten quadrillion: 12,799,999
Up to and including one hundred quadrillion: 63,999,999
Up to and including one quintillion: 63,999,999
Up to and including ten quintillion: 255,999,999
Up to and including one hundred quintillion: 1,279,999,999
Up to and including one sextillion: 1,279,999,999
 
============= t-ban: =============
t-ban numbers up to 1000: 56
[0 1 4 5 6 7 9 11 100 101 104 105 106 107 109 111 400 401 404 405 406 407 409 411 500 501 504 505 506 507 509 511 600 601 604 605 606 607 609 611 700 701 704 705 706 707 709 711 900 901 904 905 906 907 909 911]
 
t-ban numbers between 1,000 & 4,000: 0
[]
 
Counts of t-ban numbers up to one sextillion
Up to and including ten: 7
Up to and including one hundred: 9
Up to and including one thousand: 56
Up to and including ten thousand: 56
Up to and including one hundred thousand: 56
Up to and including one million: 57
Up to and including ten million: 392
Up to and including one hundred million: 785
Up to and including one billion: 5,489
Up to and including ten billion: 38,416
Up to and including one hundred billion: 76,833
Up to and including one trillion: 537,824
Up to and including ten trillion: 537,824
Up to and including one hundred trillion: 537,824
Up to and including one quadrillion: 537,825
Up to and including ten quadrillion: 3,764,768
Up to and including one hundred quadrillion: 7,529,537
Up to and including one quintillion: 52,706,752
Up to and including ten quintillion: 52,706,752
Up to and including one hundred quintillion: 52,706,752
Up to and including one sextillion: 52,706,752
 
============= subur-ban: =============
subur-ban numbers up to 1000: 35
[1 2 5 8 9 10 11 12 15 18 19 20 21 22 25 28 29 50 51 52 55 58 59 80 81 82 85 88 89 90 91 92 95 98 99]
 
subur-ban numbers between 1,000 & 4,000: 0
[]
 
Counts of subur-ban numbers up to one sextillion
Up to and including ten: 6
Up to and including one hundred: 35
Up to and including one thousand: 35
Up to and including ten thousand: 35
Up to and including one hundred thousand: 35
Up to and including one million: 36
Up to and including ten million: 216
Up to and including one hundred million: 2,375
Up to and including one billion: 2,375
Up to and including ten billion: 2,375
Up to and including one hundred billion: 2,375
Up to and including one trillion: 2,375
Up to and including ten trillion: 2,375
Up to and including one hundred trillion: 2,375
Up to and including one quadrillion: 2,375
Up to and including ten quadrillion: 2,375
Up to and including one hundred quadrillion: 2,375
Up to and including one quintillion: 2,375
Up to and including ten quintillion: 2,375
Up to and including one hundred quintillion: 2,375
Up to and including one sextillion: 2,375</pre>
 
Note that the limit to one sextillion is somewhat arbitrary and is just to match the task parameters.
 
This will quite happily count *-bans up to one hundred centillion. (10<sup>305</sup>) It takes longer, but still on the order of seconds, not minutes.
<pre>Counts of e-ban numbers up to one hundred centillion
...
Up to and including one hundred centillion: 35,184,372,088,831,999,999,999,999,999,999,999,999,999,999,999,999,999,999,999</pre>
 
=={{header|REXX}}==