The code should take input a text (not mandatory can be anything file, stdin, string for JavaScript, etc):
This is a text and a number: 31.
The output should contain the words with their number of occurrence, sorted by the number of occurrences in descending order:
a:2
and:1
is:1
number:1
This:1
text:1
31:1
Notice that 31 is a word, so a word is anything alpha-numeric, number are not acting as separators so for example 0xAF
qualifies as a word. Separators will be anything that is not alpha-numeric including .
(dot) and -
(hyphen) thus i.e.
or pick-me-up
would result in 2 respectively 3 words. Should be case sensitive, This
and this
would be two different words, '
would also be separator so wouldn
and t
will be 2 different words from wouldn't
.
Write the shortest code in your language of choice.
Shortest correct answer so far:
This
the same asthis
andtHIs
)? \$\endgroup\$wouldn't
2 words (wouldn
andt
)? \$\endgroup\$This
andthis
would be indeed two different words, samewouldn
andt
. \$\endgroup\$i.e.
is a word but if we let the dot all the dots at the end of phrases will be taken, same with quotes or single quotes, etc. \$\endgroup\$