-
-
Notifications
You must be signed in to change notification settings - Fork 546
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
Created New Exercise: Retree #1424
Conversation
Interesting exercise! Does it have a discussion, or is this the first place to discuss it? Here are some points:
Also, I'm happy to see more tree-based exercises as I've been thinking loud in #1388. |
Would it make sense to phrase the exercise with a theme, so that it sounds less like a hunt for an existing algorithm that one can mindlessly transcribe from pseudocode? As in, if you recognize the general pattern or somehow extract it, that's perfect, but not what's primarily encouraged. |
Yup, this is the first place for discussion..
My original intention was to add this exercise to the Prolog track. In Prolog you can implement the algorithm directly or use DCGs. Currently there are no exercises that encourage using DCGs so I thought I should add one. This exercise lets Declarative Prolog show off its best qualities, but also some of its shortcomings (i.e. not purely declarative). In short DCGs would be the theme I suggest. The Exercism docs recommend creating an exercise in this repo first. For most languages I can see this being simply "transcribing pseudocode." But in Prolog it could be useful. Is it allowable to create an exercise specifically for a language track without a problem-specifications entry? |
Wrt. In this case, for example, I'd welcome more tree-based exercises in the ML-style tracks, so we can share the exercise design process. One last comment on this exercise text proposal: Either remove the "you can generate multiple results" paragraph from the description, or add a test case that demonstrates multiple results. I would remove the paragraph and add a "hint" (extra section of the README on the language track) and a track-specific test for the multiple results: The exercise without duplicates are already difficult and interesting, and the "multiple solutions as a side-effect" is a Prolog thing. :) |
Co-Authored-By: fidelcoria <[email protected]>
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.
I like this exercise, it is a welcome addition to the existing body of exercises. Great work! I've left some comments.
@sshine I have been thinking about how to address your suggestions. I tried my best. "Bonus points" section of the README and the corresponding test were removed. I have added a little story to make the exercise less dry. Finally I added a small note at the end. I think it is just the right size hint. Big enough to encourage exerciser not to google, but small enough not to spoil the exercise. @ErikSchierboom do you resolve conversations or do I? I'm not familiar with etiquette for this feature. |
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.
Excellent story format! We're nearly there, I think.
I think your explanation of pre-order and in-order are sufficient, and if not, I think the Wikipedia link will discourage people from accidentally finding the complete solutions that are available in C, Java, Python and C# on this google search giving this page.
Should there be a test case that fails for duplicate elements, or should the function assume that there are no duplicates? We already have two negative classes of input that are easier to test; having this would be more complete, but would also introduce complexity in the exercise. I think in the case of Prolog you'd probably want to assume the input has unique elements. -- Maybe another test case that is optional to implement?
Thank you very much for your work so far. :-)
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.
Two small nits. As for resolving, that happens automatically I believe.
Co-Authored-By: fidelcoria <[email protected]>
Added a test for unique items since I don't think it adds too much complexity. And it helps point out subtle details. |
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.
Looking great! Just one final nit.
exercises/retree/canonical-data.json
Outdated
"expected": {"error": "traversals must have the same length"} | ||
}, | ||
{ | ||
"description": "Reject inconsistent traversals of same length", |
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.
I think the indentation of this test case is off (too much to the right).
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.
Other than that and we're ready to merge.
We should have a linting rule for this.
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.
We should have a linting rule for this.
Yes, we should!
This comment has been minimized.
This comment has been minimized.
A tangential pun: If we are ever to colonize the stars, eventually we'll want to send send trees in serialized form for terraforming purposes. :-D |
I look forward to implementing this exercise for Haskell, Ocaml and SML. :-) |
Great work @fidelcoria! Thanks for being patient with us reviewers :) |
Thank you! This is my first Open Source contribution. This was a good experience! |
You should be proud of yourself then! This is high quality first pull request. |
I've made a suggestion about renaming this exercise at #1451 :) |
The task is to rebuild binary trees using pre-order and in-order traversals of the original tree.
Possible tags for this exercise include: recursion, binary trees, and tree traversals.