72 lines
2.4 KiB
Markdown
72 lines
2.4 KiB
Markdown
# Word Count
|
|
|
|
Given a phrase, count the occurrences of each _word_ in that phrase.
|
|
|
|
For the purposes of this exercise you can expect that a _word_ will always be one of:
|
|
|
|
1. A _number_ composed of one or more ASCII digits (ie "0" or "1234") OR
|
|
2. A _simple word_ composed of one or more ASCII letters (ie "a" or "they") OR
|
|
3. A _contraction_ of two _simple words_ joined by a single apostrophe (ie "it's" or "they're")
|
|
|
|
When counting words you can assume the following rules:
|
|
|
|
1. The count is _case insensitive_ (ie "You", "you", and "YOU" are 3 uses of the same word)
|
|
2. The count is _unordered_; the tests will ignore how words and counts are ordered
|
|
3. Other than the apostrophe in a _contraction_ all forms of _punctuation_ are ignored
|
|
4. The words can be separated by _any_ form of whitespace (ie "\t", "\n", " ")
|
|
|
|
For example, for the phrase `"That's the password: 'PASSWORD 123'!", cried the Special Agent.\nSo I fled.` the count would be:
|
|
|
|
```text
|
|
that's: 1
|
|
the: 2
|
|
password: 2
|
|
123: 1
|
|
cried: 1
|
|
special: 1
|
|
agent: 1
|
|
so: 1
|
|
i: 1
|
|
fled: 1
|
|
```
|
|
|
|
- Note that the tests for this exercise expect the output words to be proper C strings. That is, they should be NUL terminated. See https://en.wikipedia.org/wiki/C_string_handling
|
|
|
|
## Getting Started
|
|
|
|
Make sure you have read the "Guides" section of the
|
|
[C track][c-track] on the Exercism site. This covers
|
|
the basic information on setting up the development environment expected
|
|
by the exercises.
|
|
|
|
## Passing the Tests
|
|
|
|
Get the first test compiling, linking and passing by following the [three
|
|
rules of test-driven development][3-tdd-rules].
|
|
|
|
The included makefile can be used to create and run the tests using the `test`
|
|
task.
|
|
|
|
make test
|
|
|
|
Create just the functions you need to satisfy any compiler errors and get the
|
|
test to fail. Then write just enough code to get the test to pass. Once you've
|
|
done that, move onto the next test.
|
|
|
|
As you progress through the tests, take the time to refactor your
|
|
implementation for readability and expressiveness and then go on to the next
|
|
test.
|
|
|
|
Try to use standard C99 facilities in preference to writing your own
|
|
low-level algorithms or facilities by hand.
|
|
|
|
## Source
|
|
|
|
This is a classic toy problem, but we were reminded of it by seeing it in the Go Tour.
|
|
|
|
## Submitting Incomplete Solutions
|
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
|
|
|
[c-track]: https://exercism.io/my/tracks/c
|
|
[3-tdd-rules]: http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd
|