On the C track @keiraville took the initiative of adding the high-scores exercise.
Great! The associated issue can be found on GitHub.
But I’m not sure if it’s possible to meet the original objectives of this exercise:
“an easy exercise”, “to practise: arrays as simple lists”, “instantiating a class”
A straightforward and complete translation would require the students to allocate memory dynamically, maintain a copy of the original
scores, and deallocate it in some “cleanup” function. It would also either involve creating a
struct for a dynamically-sized array that the function
scores() could return (again, with dynamically allocated memory), or a pointer as an output parameter.
That’s not a problem for somebody who has mastered the basics of the language, but I’m not sure if that can be called easy (if so, almost all exercises on the C track are easy.)
Therefore I think this C translation has to deviate a little bit from the problem-specification, either make it a little bit less easy, or avoid the need for dynamic memory allocation, and/or forgo the “class” by requiring just functions without any
What do you think might be the best option?
Did you have a similar problem on a different track?
Or am I just missing the point here?
I don’t think you are missing the point. We had a similar issue on the Python track with the exercise being flagged “easy” and yet requiring students to create a class (which ends up not being a beginner topic in Python).
After some debate, we changed the exercise to not require
classes. But once that was live for a while (I think a year maybe a little more), we had another discussion, and decided to change the exercise back and up the difficulty.
Not every operation flagged easy in one language is easy in another. Tracks need to be free to adjust difficulty and implementation to what makes sense for the group of exercises they implement, the idioms of the language, and other concerns such as teaching needs or progression. This is also why we have the ability to implement additional tests or add instruction appends – sometimes, things need massaging.
Another alternative might be to write a track-specific
high scores practice exercise variant that is closer to what you think students can tackle at the
easy C level.
Thanks. I might be a little bit focussed on the “easy” aspect because that’s explicitly mentioned in the canonical-data.json.
Currently my preferred approach would omit the “class” and the function
scores() cmpletely and just require
two three functions:
/// Return the latest score.
int latest(size_t scores_len, int *scores);
/// Return the highest score.
int personal_best(size_t scores_len, int *scores);
/// Write the three highest scores to `output` (in non-ascending order).
void personal_top_three(size_t scores_len, int *scores, int *output);
I think that’s as simple as it can get (but still uses an output-parameter).
I’d be in favor of not ascribing a difficulty in the problem specs.
Can you accomplish that by simply omitting some test cases from the canonical data, or do you need to more heavily re-work it? Because that seems fine to me as a variation.
Lemme look at the description … so you would omit the personal top three? You would probably want to do an instruction append then.
The description I show is this (emphasis mine):
Manage a game player’s High Score list.
Your task is to build a high-score component of the classic Frogger game, one of the highest selling and most addictive games of all time, and a classic of the arcade era. Your task is to write methods that return the highest score from the list, the last added score and the three highest scores.
…but I think it could be as simple as a note that says “we want you to focus on _____, so we’ve modified this exercise to only include _____”
instructions.append.md could also be used to explain the use of an output parameter here. This is what I would prefer as a student on the C track.
The linked comments in the canonical data are implicitly aimed at a certain class of programming languages. Tracks about languages that fall outside of this class – C, Haskell, Prolog, Forth, … – should feel free to ignore these comments completely.
( Comments that do not apply to a language can still inspire: perhaps there is a unusual but instructive formulation of the same problem. )
Thank you all for your input.
In the end @keiraville decided to follow the example of AWK and Fortran and keeping it simple by dropping the “class” aspect and the functions
I’ve submitted a PR to remove implementation details from the spec.
Hello, seeing how this is relating to the exercise for the upcoming July month, I’m wondering if the exercise “High Score” will also be the same for C++? Or will it keep the class or struct components?
@vaeng Just created a translation on the C++ track, I think it will be available in the next few days.
It uses a
class that receives a
std::vector in its constructor, and the task is to implement the four methods
I thought of discarding the class/struct construct and going for a purely functional way. In the end, I decided to keep the class, as it would probably be the idiomatic way as it would appear in a real game product.
It is still under review on GitHub, if you want to look at it before I publish.
Edit: the exercise is now available on the C++ track: High Scores in C++ on Exercism