Eban numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|zkl}}: reformat)
(→‎{{header|Perl 6}}: Simplify, fix problem with irregulars (didn't affect e-bans as all irregulars contain an e))
Line 430:
Considering numbers up to <strong>10<sup>21</sup></strong>, as the task directions suggest.
 
<lang perl6>use Lingua::EN::Numbers; # Version 2.4.0 or higher
 
sub nban ($seq, $n = 'e') { ($seq).map: { next if .&cardinal.contains(any($n.lc.comb)); $_ } }
Line 439:
(2 .. $upto).map: -> $o {
given $o % 3 { # Compensate for irregulars: 11 - 19
when 01 { @orders.push: [[flat (10**($o - 1) X* 110 .. 19).map(*.&nban($n)), |(10**$o X* 2 .. 9).map: *.&nban($n)], }
default { @orders.push: [flat (10**$o X* 111 ..19 9).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 @lower = |@orders[$o];.map: -> $m {
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);
flat @ban.map: *.flat;
Line 482 ⟶ 463:
(2 .. $upto).map: -> $o {
given $o % 3 { # Compensate for irregulars: 11 - 19
when 01 { @orders.push: [[flat (10**($o - 1) X* 110 .. 19).map(*.&nban($n)), |(10**$o X* 2 .. 9).map: *.&nban($n)], }
default { @orders.push: [flat (10**$o X* 111 ..19 9).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 $those;
^@orders .map: -> $o {
@count.push: 0 and next unless +@orders[$o];
my @lower$prev = |so (@orders[$o].first( { $_ ~~ /^ '1' '0'+ $/ } ) // 0 );
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 = +@lowerorders[$o] * $sum + @lowerorders[$o];
@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;
Line 579 ⟶ 548:
Up to and including one million: 57
Up to and including ten million: 392
Up to and including one hundred million: 393785
Up to and including one billion: 25,801489
Up to and including ten billion: 1938,600416
Up to and including one hundred billion: 1976,601833
Up to and including one trillion: 140537,000824
Up to and including ten trillion: 140537,000824
Up to and including one hundred trillion: 140537,000824
Up to and including one quadrillion: 140537,001825
Up to and including ten quadrillion: 9803,000764,768
Up to and including one hundred quadrillion: 9807,001529,537
Up to and including one quintillion: 752,000706,000752
Up to and including ten quintillion: 752,000706,000752
Up to and including one hundred quintillion: 752,000706,000752
Up to and including one sextillion: 752,000706,000752
 
============= subur-ban: =============
Line 608 ⟶ 577:
Up to and including one hundred thousand: 35
Up to and including one million: 36
Up to and including ten million: 215216
Up to and including one hundred million: 12,259375
Up to and including one billion: 12,259375
Up to and including ten billion: 12,259375
Up to and including one hundred billion: 12,259375
Up to and including one trillion: 12,259375
Up to and including ten trillion: 12,259375
Up to and including one hundred trillion: 12,259375
Up to and including one quadrillion: 12,259375
Up to and including ten quadrillion: 12,259375
Up to and including one hundred quadrillion: 12,259375
Up to and including one quintillion: 12,259375
Up to and including ten quintillion: 12,259375
Up to and including one hundred quintillion: 12,259375
Up to and including one sextillion: 12,259375</pre>
 
Note that the limit to one sextillion is somewhat arbitrary and is just to match the task parameters.