exercism / cpp

Exercism exercises in C++.
https://exercism.org/tracks/cpp
MIT License
252 stars 205 forks source link

Add exercise two-bucket. #785

Closed siebenschlaefer closed 6 months ago

siebenschlaefer commented 6 months ago

This is a translation of the "two-bucket" exercise.

I've decided to provide the complete .h file with a definition of the enum, the struct that holds the result, and a declaration of the function. Although I like the idea of letting the students write their own .h file by extracting the interface from the tests I think in this case it would be just chore. But feel free to object, that's not a strong preference of mine.

The thing that bothered me the most is how to handle cases that are not possible to solve. Requiring exceptions for "expected" error cases that might occur frequently and are part of the normal control flow is IMHO bad style. If I could I would use C++23's std::expected but that's not an option at the moment. Here are some alternatives:

If any of you has an idea, I'm all ears.

siebenschlaefer commented 6 months ago

The example solution was just the simplest solution I could think of. There is a more general approach that treats this problem as a breadth-first search without inspecting its properties and a mathematical approach that solves a Diophantine equation (I was obsessed with this problem for a week in November and am kind of proud that I found this one.)

I definitely want to write either approaches or a blog post but not in the next two weeks.
As for the mentoring notes, I want to wait a little bit until we have a reasonable sample of solutions from which we can extract talking points.

vaeng commented 6 months ago

I definitely want to write either approaches or a blog post but not in the next two weeks.

The exercise is not due to be featured in #48in24 until October, so there is a lot of time :)