mirror of
https://github.com/ArthurDanjou/exercism-rust.git
synced 2026-01-14 20:19:29 +01:00
1.5 KiB
1.5 KiB
Hints
General
1. Write a function divmod which returns both the quotient and remainder of a division
- Don't worry about optimizing for efficiency; the naive implementation is fine
2. Write an iterator adaptor evens which returns the even items from an arbitrary iterator
- Just chain together the suggested methods and everything will work out
- A number
nis even ifn % 2 == 0 - A closure is a function with abbreviated syntax: the argument name(s) go within a pair of
|symbols, and the expression follows. Unlike normal functions, it is not always necessary to explicitly state the type of each argument, just the name. For example, here is how you can construct an iterator of odd squares:(0..).map(|n| 2 * n + 1).map(|n| n * n).
3. Implement a manhattan method on a Position tuple struct
- Don't worry about method syntax; just replacing the
unimplementedportion within theimpl Positionblock will do the right thing. - Consider that some values within a
Positionmay be negative, but a distance is never negative. - Calculating the absolute value is built-in