- We have file with a single word per line. Read the file.
- Use a
HashMap
to count the number of times each word appears. - Print the words and their occurrences in 2 columns: first the number of occurrences, then the word itself
- Change the program to sort the words by number of occurrence (ascending or descending)
Note: the checks here don't have to be 100% mathematically correct. The goal is to use traits to compose functionality.
- Define a type for Rectangle.
- Define a trait
Intersects<T>
- it must have a single function to check if the object it's called on intersects another
- Write an implementation for Rectangle to check that it intersects other rectangles
- Add some other shapes (like Circle or Triangle)
- add implementations for
Intersects
to check intersections for each pair of shapes
- add implementations for
- Define an enum
Shape
, with a variant to contain each kind of shape- optionally also implement
Intersects
forShape
(hint: you can just match and call the previous impls)
- optionally also implement
- Establish a simple text format for each shape. Example:
- "rectangle 2 4 20 30" can mean a rectangle, followed by two x & y pairs for 2 corners
- "circle 10 10 5" can mean a circle, centered at point 10 10 (x y), with radius 5
- Write a file with some shapes in the format above, one per line
- Read the file, and parse into a
Vec<Shape>
- hint: use
split_whitespace
on each line
- hint: use
- Compute intersection sets:
- divide the vector into a
Vec<HashSet<Shape>>
- all shapes in a set must intersect at least one shape in that set
- the sets must be disjoint (no shape from set 1 may intersect a shape from set 2, etc.)
- divide the vector into a
- Print the intersection sets