Exercise: Squares Sum
squares-sum
Implement sum_squares(n) which returns the sum of squares from 1..=n.
src/lib.rs
โ ๏ธ Try the exercise first! Show Solution
pub fn sum_squares(n: u64) -> u64 {
(1..=n).map(|x| x*x).sum()
}
๐งช Tests
View Test Code
#[test]
fn small() {
assert_eq!(sum_squares(3), 14);
}
๐ค Reflection
- Why might `reveal=always` be useful for quick-reference exercises?