Comments on Word Count Tool
Post
Word Count Tool
In Google Docs, the word count tool looks like this:
Pages would not make sense, but your goal is to implement every other count.
Definitions
Words are strings of text separated by any amount of whitespace (spaces, tabs, newlines). Characters are all printable bytes*. For the sake of this challenge, you may assume all inputs will consist of printable bytes. Note that Google Docs does not count newlines in its character count, so you must do the same.
*I define printable bytes as the variable string.printable in Python, which is shown below.
>>> string.printable
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
Input
A string of text, or a list of strings instead of a multiline string if you wish.
Output
The 3 counts (words, characters, characters without spaces) in any order, and in an array if you like.
Examples
Input -> [words, characters, characters without spaces]
"Hello world" -> [2, 11, 10]
"H3ll0 w0r1d" -> [2, 12, 10]
"Hello \t\nworld" -> [2, 12, 11]
"\n\n\n" -> [0, 0, 0]
" " -> [0, 3, 0]
This is code golf, so shortest code wins.
[Ruby], 55 bytes -> …
3y ago
[APL (Dyalog Unicode)], 27 byt …
3y ago
Japt v2.0a0, 19 18 17 bytes …
3y ago
[Python 3.8], 73 bytes …
2y ago
[Wolfram Language (Mathematica …
2y ago
JavaScript (Node.js), 60 bytes …
2y ago
Lua 5.4, 62 bytes ``` lua …
2y ago
Ruby, 48 bytes ```ruby ->a …
3y ago
[Haskell], 47 bytes …
3y ago
1 comment thread