You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
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
n
is 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
unimplemented
portion within theimpl Position
block will do the right thing. - Consider that some values within a
Position
may be negative, but a distance is never negative. - Calculating the absolute value is built-in