Four is the number of letters in the ...: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: Update for module change) |
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Update for updated module) |
||
Line 542: | Line 542: | ||
Uses the Lingua::EN::Numbers module to generate both cardinal and ordinal numbers. This module places commas in number words between 3-orders-of-magnitude clusters. E.G. <code>12345678.&ordinal</code> becomes: twelve million, three hundred forty-five thousand, six hundred seventy-eighth. Uses a custom 'no-commas' routine to filter them out for accurate character counts. Generates the 'sentence' lazily so only the words needed are ever calculated and reified. |
Uses the Lingua::EN::Numbers module to generate both cardinal and ordinal numbers. This module places commas in number words between 3-orders-of-magnitude clusters. E.G. <code>12345678.&ordinal</code> becomes: twelve million, three hundred forty-five thousand, six hundred seventy-eighth. Uses a custom 'no-commas' routine to filter them out for accurate character counts. Generates the 'sentence' lazily so only the words needed are ever calculated and reified. |
||
<lang perl6>use Lingua::EN::Numbers; |
<lang perl6>use Lingua::EN::Numbers; |
||
no-commas(True); |
|||
my $index = 1; |
my $index = 1; |
||
my @sentence = flat 'Four is the number of letters in the first word of this sentence, '.words, |
my @sentence = flat 'Four is the number of letters in the first word of this sentence, '.words, |
||
{ @sentence[$index++].&alpha.&cardinal, 'in', 'the', |($index.&ordinal |
{ @sentence[$index++].&alpha.&cardinal, 'in', 'the', |($index.&ordinal ~ ',').words } ... * ; |
||
sub alpha ( $str ) { $str.subst(/\W/, '', :g).chars } |
sub alpha ( $str ) { $str.subst(/\W/, '', :g).chars } |
||
sub no-commas ( $str ) { $str.subst(',', '', :g) } |
|||
sub count ( $index ) { @sentence[^$index].join(' ').chars ~ " characters in the sentence, up to and including this word.\n" } |
sub count ( $index ) { @sentence[^$index].join(' ').chars ~ " characters in the sentence, up to and including this word.\n" } |
||