You've already forked rust-tutor
- create exercise vec statistics calculator (shout out claude) - finish hacky solution (it works... but at what cost) - update current state
26 lines
913 B
Markdown
26 lines
913 B
Markdown
# Exercise: Vec Statistics Calculator
|
|
|
|
**Concepts practiced:** Vec operations, HashMap for counting, basic math functions
|
|
**Objective:** Build a simple stats calculator that takes a list of numbers and returns basic statistics
|
|
|
|
## Requirements:
|
|
- Create a function `calculate_stats(numbers: Vec<i32>) -> (f64, i32, i32)` that returns (mean, median, mode)
|
|
- Use Vec sorting for median calculation
|
|
- Use HashMap for mode calculation (most frequent number)
|
|
- Handle edge cases (empty vec should panic with clear message)
|
|
|
|
## Success criteria:
|
|
- Code compiles and runs
|
|
- Test with `vec![1, 2, 3, 3, 4, 5]` returns approximately `(3.0, 3, 3)`
|
|
|
|
## Stretch goal:
|
|
Return a struct instead of tuple for better readability
|
|
|
|
## Getting Started:
|
|
1. `cd exercises`
|
|
2. `cargo new vec-stats`
|
|
3. `cd vec-stats`
|
|
4. Implement the function in `src/main.rs` or `src/lib.rs`
|
|
5. Test with the example input
|
|
|
|
Expected time: 30-45 minutes |