Four is the number of letters in the ...: Difference between revisions

Content added Content deleted
(Added Perl example)
(→‎{{header|Perl}}: Lingua::EN::Numbers puts 'and' in the ordinal/cardinal numbers. Filter them out for accurate character counts.)
Line 394: Line 394:


sub alpha { my($s) = @_; $s =~ s/\W//gi; length $s }
sub alpha { my($s) = @_; $s =~ s/\W//gi; length $s }
sub no_c { my($s) = @_; $s =~ s/,//g; return $s }
sub no_c { my($s) = @_; $s =~ s/\ and|,//g; return $s }
sub count { length(join ' ', @sentence[0..-1+$_[0]]) . " characters in the sentence, up to and including this word.\n" }
sub count { length(join ' ', @sentence[0..-1+$_[0]]) . " characters in the sentence, up to and including this word.\n" }


Line 405: Line 405:
print "\n" . count(201) . "\n";
print "\n" . count(201) . "\n";


for (1e3, 1e4, 1e5, 1e6) {
for (1e3, 1e4, 1e5, 1e6, 1e7) {
extend_to($_);
extend_to($_);
print
print
Line 422: Line 422:
1203 characters in the sentence, up to and including this word.
1203 characters in the sentence, up to and including this word.


One thousandth word, 'in' has 2 characters.
One thousandth word, 'in' has 2 characters.
6048 characters in the sentence, up to and including this word.
6249 characters in the sentence, up to and including this word.


Ten thousandth word, 'in' has 2 characters.
Ten thousandth word, 'in' has 2 characters.
61055 characters in the sentence, up to and including this word.
64097 characters in the sentence, up to and including this word.


One hundred thousandth word, 'the' has 3 characters.
One hundred thousandth word, 'one' has 3 characters.
627301 characters in the sentence, up to and including this word.
659455 characters in the sentence, up to and including this word.


One millionth word, 'five' has 4 characters.
One millionth word, 'the' has 3 characters.
6781802 characters in the sentence, up to and including this word.</pre>
7113560 characters in the sentence, up to and including this word.

Ten millionth word, 'thousand' has 8 characters.
70995729 characters in the sentence, up to and including this word.</pre>


=={{header|Perl 6}}==
=={{header|Perl 6}}==