|
1 | 1 | # Instructions |
2 | 2 |
|
3 | | -Given a phrase, count the occurrences of each _word_ in that phrase. |
| 3 | +Your task is to count how many times each word occurs in a subtitle of a drama. |
4 | 4 |
|
5 | | -For the purposes of this exercise you can expect that a _word_ will always be one of: |
| 5 | +The subtitles from these dramas use only ASCII characters. |
6 | 6 |
|
7 | | -1. A _number_ composed of one or more ASCII digits (ie "0" or "1234") OR |
8 | | -2. A _simple word_ composed of one or more ASCII letters (ie "a" or "they") OR |
9 | | -3. A _contraction_ of two _simple words_ joined by a single apostrophe (ie "it's" or "they're") |
| 7 | +The characters often speak in casual English, using contractions like _they're_ or _it's_. |
| 8 | +Though these contractions come from two words (e.g. _we are_), the contraction (_we're_) is considered a single word. |
10 | 9 |
|
11 | | -When counting words you can assume the following rules: |
| 10 | +Words can be separated by any form of punctuation (e.g. ":", "!", or "?") or whitespace (e.g. "\t", "\n", or " "). |
| 11 | +The only punctuation that does not separate words is the apostrophe in contractions. |
12 | 12 |
|
13 | | -1. The count is _case insensitive_ (ie "You", "you", and "YOU" are 3 uses of the same word) |
14 | | -2. The count is _unordered_; the tests will ignore how words and counts are ordered |
15 | | -3. Other than the apostrophe in a _contraction_ all forms of _punctuation_ are ignored |
16 | | -4. The words can be separated by _any_ form of whitespace (ie "\t", "\n", " ") |
| 13 | +Numbers are considered words. |
| 14 | +If the subtitles say _It costs 100 dollars._ then _100_ will be its own word. |
17 | 15 |
|
18 | | -For example, for the phrase `"That's the password: 'PASSWORD 123'!", cried the Special Agent.\nSo I fled.` the count would be: |
| 16 | +Words are case insensitive. |
| 17 | +For example, the word _you_ occurs three times in the following sentence: |
| 18 | + |
| 19 | +> You come back, you hear me? DO YOU HEAR ME? |
| 20 | +
|
| 21 | +The ordering of the word counts in the results doesn't matter. |
| 22 | + |
| 23 | +Here's an example that incorporates several of the elements discussed above: |
| 24 | + |
| 25 | +- simple words |
| 26 | +- contractions |
| 27 | +- numbers |
| 28 | +- case insensitive words |
| 29 | +- punctuation (including apostrophes) to separate words |
| 30 | +- different forms of whitespace to separate words |
| 31 | + |
| 32 | +`"That's the password: 'PASSWORD 123'!", cried the Special Agent.\nSo I fled.` |
| 33 | + |
| 34 | +The mapping for this subtitle would be: |
19 | 35 |
|
20 | 36 | ```text |
21 | | -that's: 1 |
22 | | -the: 2 |
23 | | -password: 2 |
24 | 37 | 123: 1 |
25 | | -cried: 1 |
26 | | -special: 1 |
27 | 38 | agent: 1 |
28 | | -so: 1 |
29 | | -i: 1 |
| 39 | +cried: 1 |
30 | 40 | fled: 1 |
| 41 | +i: 1 |
| 42 | +password: 2 |
| 43 | +so: 1 |
| 44 | +special: 1 |
| 45 | +that's: 1 |
| 46 | +the: 2 |
31 | 47 | ``` |
0 commit comments