Eban numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: typo) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Fix error in assumptions. e-ban numbers were correct, but the algorithm needed some tweaks for the general case.) |
||
Line 301: | Line 301: | ||
===Algorithmically generate / count=== |
===Algorithmically generate / count=== |
||
Alternately, a translation of Perl 6 |
Alternately, a partial translation of Perl 6. Does not need to actually generate the e-ban numbers to count them. Display counts up to 10**21. |
||
<lang perl>use strict; |
<lang perl>use strict; |
||
Line 354: | Line 354: | ||
} |
} |
||
for my $t ('e |
for my $t ('e') { |
||
my @bans = enumerate($t, 4); |
my @bans = enumerate($t, 4); |
||
my @count = count($t, my $max = 21); |
my @count = count($t, my $max = 21); |
||
Line 407: | Line 407: | ||
Up to and including ten quintillion: 255,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 hundred quintillion: 1,279,999,999 |
||
Up to and including one sextillion: 1,279,999,999 |
Up to and including one sextillion: 1,279,999,999</pre> |
||
============= 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 (inclusive): 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: 393 |
|||
Up to and including one billion: 2,745 |
|||
Up to and including ten billion: 19,208 |
|||
Up to and including one hundred billion: 19,209 |
|||
Up to and including one trillion: 134,456 |
|||
Up to and including ten trillion: 134,456 |
|||
Up to and including one hundred trillion: 134,456 |
|||
Up to and including one quadrillion: 134,457 |
|||
Up to and including ten quadrillion: 941,192 |
|||
Up to and including one hundred quadrillion: 941,193 |
|||
Up to and including one quintillion: 6,588,344 |
|||
Up to and including ten quintillion: 6,588,344 |
|||
Up to and including one hundred quintillion: 6,588,344 |
|||
Up to and including one sextillion: 6,588,344 |
|||
============= 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 (inclusive): 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: 1,295 |
|||
Up to and including one billion: 1,295 |
|||
Up to and including ten billion: 1,295 |
|||
Up to and including one hundred billion: 1,295 |
|||
Up to and including one trillion: 1,295 |
|||
Up to and including ten trillion: 1,295 |
|||
Up to and including one hundred trillion: 1,295 |
|||
Up to and including one quadrillion: 1,295 |
|||
Up to and including ten quadrillion: 1,295 |
|||
Up to and including one hundred quadrillion: 1,295 |
|||
Up to and including one quintillion: 1,295 |
|||
Up to and including ten quintillion: 1,295 |
|||
Up to and including one hundred quintillion: 1,295 |
|||
Up to and including one sextillion: 1,295</pre> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |
||
Line 495: | Line 435: | ||
sub enumerate ($n, $upto) { |
sub enumerate ($n, $upto) { |
||
my @ban |
my @ban = [nban(1 .. 99, $n)],; |
||
my @orders |
my @orders; |
||
(2 .. $upto).map: -> $o { |
|||
given $o % 3 { # Compensate for irregulars: 11 - 19 |
|||
next unless +$_; |
|||
when 0 { @orders.push: [[flat (10**$o X* 1..9).map: *.&nban($n)], |
|||
[flat (10**$o X* 11..19).map: *.&nban($n)]]} |
|||
when 1 { @orders.push: [flat (10**$o X* 2..9).map: *.&nban($n)] } |
|||
default { @orders.push: [flat (10**$o X* 1..9).map: *.&nban($n)] } |
|||
} |
|||
} |
|||
my @those; |
|||
^@orders .map: -> $o { |
|||
@ban.push: [] and next unless +@orders[$o]; |
|||
my @these; |
my @these; |
||
my @lower = |@orders[$o]; |
|||
my @upper = []; |
|||
if @orders[$o][0].^name eq 'Array' { |
|||
@lower = |@orders[$o][0]; |
|||
@upper = |@orders[$o][1]; |
|||
} |
|||
@lower.map: -> $m { |
|||
@these.push: $m; |
|||
for ^@ban -> $b { |
|||
next unless +@ban[$b]; |
|||
@these.push: $_ for (flat @ban[$b]) »+» $m ; |
|||
} |
|||
} |
|||
@ban.push: @those.clone if +@those; |
|||
@those = (); |
|||
@upper.map: -> $m { |
|||
@those.push: $m; |
|||
for ^(@ban) -> $b { |
|||
next unless +@ban[$b]; |
|||
@those.push: $_ for (flat @ban[$b]) »+» $m ; |
|||
} |
|||
} |
|||
@ban.push: @these; |
|||
} |
} |
||
@ban.push: @those.clone if +@those; |
|||
@ban.unshift(0) if nban(0, $n); |
@ban.unshift(0) if nban(0, $n); |
||
@ban |
flat @ban.map: *.flat; |
||
} |
} |
||
sub count ($n, $upto) { |
sub count ($n, $upto) { |
||
my @orders |
my @orders; |
||
(2 .. $upto).map: -> $o { |
|||
given $o % 3 { # Compensate for irregulars: 11 - 19 |
|||
when 0 { @orders.push: [[flat (10**$o X* 1 .. 9).map: *.&nban($n)], |
|||
[flat (10**$o X* 11..19).map: *.&nban($n)]]} |
|||
when 1 { @orders.push: [flat (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); |
my @count = +nban(1 .. 99, $n); |
||
my $those; |
|||
@count.push: @count.sum * @orders[$_] + @orders[$_] for ^(+@orders - 1); |
|||
^@orders .map: -> $o { |
|||
@count.push: 0 and next unless +@orders[$o]; |
|||
my @lower = |@orders[$o]; |
|||
my @upper = []; |
|||
if @orders[$o][0].^name eq 'Array' { |
|||
@lower = |@orders[$o][0]; |
|||
@upper = |@orders[$o][1]; |
|||
} |
|||
my $prev = so (@lower.first( { $_ ~~ /^ '1' '0'+ $/ } ) // 0 ); |
|||
my $sum = @count.sum; |
|||
my $these = +@lower * $sum + @lower; |
|||
@count[1 + $o] += $those if $those; |
|||
$those = +@upper * $sum + @upper; |
|||
$these-- if $prev; |
|||
@count[1 + $o] += $these; |
|||
++@count[$o] if $prev; |
|||
} |
|||
@count[*-1] += $those if $those and $upto % 3 == 1; |
|||
++@count[0] if nban(0, $n); |
++@count[0] if nban(0, $n); |
||
for ^(@count - 1) { if @orders[$_].contains(1) { @count[$_]++; @count[$_ + 1]-- } } |
|||
[\+] @count; |
[\+] @count; |
||
} |
} |
||
Line 532: | Line 528: | ||
"\nCounts of {$n}-ban numbers up to {cardinal 10**$upto}" |
"\nCounts of {$n}-ban numbers up to {cardinal 10**$upto}" |
||
; |
; |
||
my $s = max (1..$upto).map: { (10**$_).&cardinal.chars }; |
my $s = max (1..$upto).map: { (10**$_).&cardinal.chars }; |
||
@counts.unshift: @bans.first: * > 10, :k; |
@counts.unshift: @bans.first: * > 10, :k; |
||
for |
for ^$upto -> $c { |
||
printf "Up to and including %{$s}s: %s\n", cardinal(10**($ |
printf "Up to and including %{$s}s: %s\n", cardinal(10**($c+1)), comma(@counts[$c]); |
||
} |
} |
||
}</lang> |
}</lang> |
||
Line 585: | Line 582: | ||
Up to and including ten million: 392 |
Up to and including ten million: 392 |
||
Up to and including one hundred million: 393 |
Up to and including one hundred million: 393 |
||
Up to and including one billion: 2, |
Up to and including one billion: 2,801 |
||
Up to and including ten billion: 19, |
Up to and including ten billion: 19,600 |
||
Up to and including one hundred billion: 19, |
Up to and including one hundred billion: 19,601 |
||
Up to and including one trillion: |
Up to and including one trillion: 140,000 |
||
Up to and including ten trillion: |
Up to and including ten trillion: 140,000 |
||
Up to and including one hundred trillion: |
Up to and including one hundred trillion: 140,000 |
||
Up to and including one quadrillion: |
Up to and including one quadrillion: 140,001 |
||
Up to and including ten quadrillion: |
Up to and including ten quadrillion: 980,000 |
||
Up to and including one hundred quadrillion: |
Up to and including one hundred quadrillion: 980,001 |
||
Up to and including one quintillion: |
Up to and including one quintillion: 7,000,000 |
||
Up to and including ten quintillion: |
Up to and including ten quintillion: 7,000,000 |
||
Up to and including one hundred quintillion: |
Up to and including one hundred quintillion: 7,000,000 |
||
Up to and including one sextillion: |
Up to and including one sextillion: 7,000,000 |
||
============= subur-ban: ============= |
============= subur-ban: ============= |
||
Line 613: | Line 610: | ||
Up to and including one hundred thousand: 35 |
Up to and including one hundred thousand: 35 |
||
Up to and including one million: 36 |
Up to and including one million: 36 |
||
Up to and including ten million: |
Up to and including ten million: 215 |
||
Up to and including one hundred million: 1, |
Up to and including one hundred million: 1,259 |
||
Up to and including one billion: 1, |
Up to and including one billion: 1,259 |
||
Up to and including ten billion: 1, |
Up to and including ten billion: 1,259 |
||
Up to and including one hundred billion: 1, |
Up to and including one hundred billion: 1,259 |
||
Up to and including one trillion: 1, |
Up to and including one trillion: 1,259 |
||
Up to and including ten trillion: 1, |
Up to and including ten trillion: 1,259 |
||
Up to and including one hundred trillion: 1, |
Up to and including one hundred trillion: 1,259 |
||
Up to and including one quadrillion: 1, |
Up to and including one quadrillion: 1,259 |
||
Up to and including ten quadrillion: 1, |
Up to and including ten quadrillion: 1,259 |
||
Up to and including one hundred quadrillion: 1, |
Up to and including one hundred quadrillion: 1,259 |
||
Up to and including one quintillion: 1, |
Up to and including one quintillion: 1,259 |
||
Up to and including ten quintillion: 1, |
Up to and including ten quintillion: 1,259 |
||
Up to and including one hundred quintillion: 1, |
Up to and including one hundred quintillion: 1,259 |
||
Up to and including one sextillion: 1, |
Up to and including one sextillion: 1,259</pre> |
||
Note that the limit to one sextillion is somewhat arbitrary and is just to match the task parameters. |
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 |
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 |
<pre>Counts of e-ban numbers up to one hundred centillion |
||
... |
... |