WeCodeAcademy

Step 1: Define the tool

In this project you build the same small tool four times: a word counter that prints how often each word appears, most frequent first (ties alphabetically). You will write it in C (everything by hand), C++ (containers and algorithms), Rust (ownership and safety) and Go (simple and fast). Seeing one problem solved four ways shows what each language gives you, and what it asks of you.

The specification. Input: the text The quick brown fox jumps over the lazy dog. The end!. Rules: ignore case (The and the are the same word), treat anything that is not a letter as a separator, count each word, and sort by count (highest first) then alphabetically. Expected output: the appears 3 times and the other eight words once each. All four programs below print identical output, and every example's output was produced by really compiling and running it.

Before any code, here is the idea in the Unix terminal you already know. Sorting groups equal words together, which is the heart of counting:

Examplebash
Open in editor »
/ $

The algorithm in four steps: (1) lowercase and split into words; (2) keep a table from word to count; (3) put the table entries in a list; (4) sort the list and print it.

Quick check

Why does the tool lowercase the text first?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.