-
Notifications
You must be signed in to change notification settings - Fork 544
Add POV exercise #2094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add POV exercise #2094
Conversation
Co-authored-by: devcyjung <[email protected]>
rustc has actually gotten smart enough to not warn about unused variables with the type `PhantomData`. Pretty cool!
This would unnecessarily prime students to use a vector internally.
dc007fc to
d189ccb
Compare
Avoiding unnecessary allocations is important to the design of Rust. In order to ensure students do not cheat, we add a test with a custom, non-Clone type so their implementation fails to compile if they add the Clone bound. * TODO: add custom test with non-Clone item type to prevent cheating * TODO: add myself to authors in pov/.meta/config.json
ddc6473 to
be808c6
Compare
|
supersedes #2077 I already had a lot of back-and-forth with the original author. I guess they tapped out at some point 🙁 I pinged them after a month and still haven't heard back a second month later. I think this is a pretty cool exercise and unique on the track. No other exercise deals with mutating trees. So I want to get it over the finish line. I made sure to keep the original author in I did change quite a bit of stuff though. The API design was geared towards immutability before, I changed that to allow an implementation without unnecessary allocations. I think the mutable API is not only important because of performance, but also because cloning everything kinda takes away the challenge unique to Rust in this case. That would be a missed opportunity for special learning moments in my opinion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I don't think I have enough knowledge of rust to solve this mutably. I couldn't think of a way to implement the tree swapping that the borrow checker approved of. Looking at example.rs it looks like I had to mem::swap which I haven't done in ages, if ever, so I can't say I reached for it.
I agree that it would be much less interesting if you could clone everything. In it's current state this is a very short exercise that requires you to know the borrow checker well and know some graph theory. I think this would be one of the best exercises on the track.
I only have some minor feedback:
path_tocould maybe be renamed topath_betweenpath_toonly presents a challenge of implementing a tree search algorithm, whichpov_fromalso requires you to implement- as a twist, it might make sense to make
path_toimmutable to prevent the student from reusingpov_fromand having them implement a tree search for two nodes from the root and returning the path between them
- as a twist, it might make sense to make
I'll approve this so that you have the discretion to disagree with those points and merge 😄
That's a great point. The name comes from problem-specifications, so I didn't question it. But we can just rename it.
Also a great thought. I think in this case it's kind of a feature that So, I think I'll leave that part as-is. |
|
Thanks for the review! |
Co-authored-by: devcyjung [email protected]