Eban numbers: Difference between revisions
Content deleted Content added
m →{{header|zkl}}: reformat |
Thundergnat (talk | contribs) →{{header|Perl 6}}: Simplify, fix problem with irregulars (didn't affect e-bans as all irregulars contain an e) |
||
Line 430: | Line 430: | ||
Considering numbers up to <strong>10<sup>21</sup></strong>, as the task directions suggest. |
Considering numbers up to <strong>10<sup>21</sup></strong>, as the task directions suggest. |
||
<lang perl6>use Lingua::EN::Numbers; |
<lang perl6>use Lingua::EN::Numbers; |
||
sub nban ($seq, $n = 'e') { ($seq).map: { next if .&cardinal.contains(any($n.lc.comb)); $_ } } |
sub nban ($seq, $n = 'e') { ($seq).map: { next if .&cardinal.contains(any($n.lc.comb)); $_ } } |
||
Line 439: | Line 439: | ||
(2 .. $upto).map: -> $o { |
(2 .. $upto).map: -> $o { |
||
given $o % 3 { # Compensate for irregulars: 11 - 19 |
given $o % 3 { # Compensate for irregulars: 11 - 19 |
||
when |
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)] } |
|||
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 { |
^@orders .map: -> $o { |
||
@ban.push: [] and next unless +@orders[$o]; |
@ban.push: [] and next unless +@orders[$o]; |
||
my @these; |
my @these; |
||
@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; |
@these.push: $m; |
||
for ^@ban -> $b { |
for ^@ban -> $b { |
||
next unless +@ban[$b]; |
next unless +@ban[$b]; |
||
@these.push: $_ for (flat @ban[$b]) »+» $m ; |
@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: @these; |
||
} |
} |
||
@ban.push: @those.clone if +@those; |
|||
@ban.unshift(0) if nban(0, $n); |
@ban.unshift(0) if nban(0, $n); |
||
flat @ban.map: *.flat; |
flat @ban.map: *.flat; |
||
Line 482: | Line 463: | ||
(2 .. $upto).map: -> $o { |
(2 .. $upto).map: -> $o { |
||
given $o % 3 { # Compensate for irregulars: 11 - 19 |
given $o % 3 { # Compensate for irregulars: 11 - 19 |
||
when |
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)] } |
|||
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; |
|||
^@orders .map: -> $o { |
^@orders .map: -> $o { |
||
@count.push: 0 and next unless +@orders[$o]; |
@count.push: 0 and next unless +@orders[$o]; |
||
my |
my $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 $sum = @count.sum; |
||
my $these = +@ |
my $these = +@orders[$o] * $sum + @orders[$o]; |
||
@count[1 + $o] += $those if $those; |
|||
$those = +@upper * $sum + @upper; |
|||
$these-- if $prev; |
$these-- if $prev; |
||
@count[1 + $o] += $these; |
@count[1 + $o] += $these; |
||
++@count[$o] if $prev; |
++@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); |
||
[\+] @count; |
[\+] @count; |
||
Line 579: | Line 548: | ||
Up to and including one million: 57 |
Up to and including one million: 57 |
||
Up to and including ten million: 392 |
Up to and including ten million: 392 |
||
Up to and including one hundred million: |
Up to and including one hundred million: 785 |
||
Up to and including one billion: |
Up to and including one billion: 5,489 |
||
Up to and including ten billion: |
Up to and including ten billion: 38,416 |
||
Up to and including one hundred billion: |
Up to and including one hundred billion: 76,833 |
||
Up to and including one trillion: |
Up to and including one trillion: 537,824 |
||
Up to and including ten trillion: |
Up to and including ten trillion: 537,824 |
||
Up to and including one hundred trillion: |
Up to and including one hundred trillion: 537,824 |
||
Up to and including one quadrillion: |
Up to and including one quadrillion: 537,825 |
||
Up to and including ten quadrillion: |
Up to and including ten quadrillion: 3,764,768 |
||
Up to and including one hundred quadrillion: |
Up to and including one hundred quadrillion: 7,529,537 |
||
Up to and including one quintillion: |
Up to and including one quintillion: 52,706,752 |
||
Up to and including ten quintillion: |
Up to and including ten quintillion: 52,706,752 |
||
Up to and including one hundred quintillion: |
Up to and including one hundred quintillion: 52,706,752 |
||
Up to and including one sextillion: |
Up to and including one sextillion: 52,706,752 |
||
============= subur-ban: ============= |
============= subur-ban: ============= |
||
Line 608: | Line 577: | ||
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: 216 |
||
Up to and including one hundred million: |
Up to and including one hundred million: 2,375 |
||
Up to and including one billion: |
Up to and including one billion: 2,375 |
||
Up to and including ten billion: |
Up to and including ten billion: 2,375 |
||
Up to and including one hundred billion: |
Up to and including one hundred billion: 2,375 |
||
Up to and including one trillion: |
Up to and including one trillion: 2,375 |
||
Up to and including ten trillion: |
Up to and including ten trillion: 2,375 |
||
Up to and including one hundred trillion: |
Up to and including one hundred trillion: 2,375 |
||
Up to and including one quadrillion: |
Up to and including one quadrillion: 2,375 |
||
Up to and including ten quadrillion: |
Up to and including ten quadrillion: 2,375 |
||
Up to and including one hundred quadrillion: |
Up to and including one hundred quadrillion: 2,375 |
||
Up to and including one quintillion: |
Up to and including one quintillion: 2,375 |
||
Up to and including ten quintillion: |
Up to and including ten quintillion: 2,375 |
||
Up to and including one hundred quintillion: |
Up to and including one hundred quintillion: 2,375 |
||
Up to and including one sextillion: |
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. |
Note that the limit to one sextillion is somewhat arbitrary and is just to match the task parameters. |