-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add Word Counter Exercise with Solution #2717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
d15ddef
to
c592d08
Compare
c592d08
to
5211436
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of comments below, but before addressing those..
Is there some context for what you're trying to accomplish here? The course typically has one exercise per segment, but this adds a second for this segment. Are you suggesting replacing the existing exercise? Why? What pedagogical advantage does the new exercise have over the existing exercise? Have you tried this exercise with students?
All of these questions might have answers, and we might adopt the exercise, but they will need to be discussed before we can do so.
|
||
[View solution](word_counter_solution.md) | ||
|
||
```rust,editable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use anchors to include the non-solution parts of the code.
1. Implement the `count_words` function that takes a string slice and returns a `HashMap<String, u32>` | ||
2. Make the word counting case-insensitive (e.g., "The" and "the" count as the same word) | ||
3. Implement the `print_word_counts` function that prints the word counts in alphabetical order | ||
4. Add tests for: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We haven't talked about testing yet. Most exercises focus on getting the task solved, rather than testing.
src/std-types/word_counter.md
Outdated
2. Add statistics like total words, unique words, and average word length | ||
3. Find and display the most common words | ||
|
||
[View solution](word_counter_solution.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We typically don't include a link, since it is just the next slide.
src/std-types/word_counter.md
Outdated
assert_eq!(counter.word_count("hello"), 2); | ||
assert_eq!(counter.word_count("rust"), 1); | ||
assert_eq!(counter.word_count("world"), 1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing closing triple-backtick
src/std-types/word_counter.rs
Outdated
@@ -0,0 +1,140 @@ | |||
// ANCHOR: word_counter | |||
use std::collections::HashMap; | |||
use clap::Parser; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't talk about clap
in fundamentals. And, command-line interface is sort of out-of-scope for this exercise, anyway -- the assignment relates to counting words, and the segment is about types in std
. This should probably just take a static string as input.
src/std-types/word_counter.pdb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should not be included (I'm not even sure what creates it?)
src/std-types/word_counter.exe
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely do not check in the windows executable!
@@ -0,0 +1,110 @@ | |||
use std::collections::HashMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is Rust, not Markdown.
src/std-types/word_counter_test
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, please do not add binary files
test-exercise/main.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be a fibonacci implementation encoded in UTF-16?!?
Sir please now cheak it |
This pull request adds a new word counter exercise to the comprehensive-rust course. The exercise includes:
src/std-types/word_counter.rs
word_counter_solution.md
The exercise helps learners understand:
This is my first contribution to the comprehensive-rust course. I'm open to any feedback or suggestions for improvement.