As an easy exercise that is linked to in learning mode, I think it is important that the Eliud’s Eggs exercise gets a Dig Deeper section with approaches. I offer to create a PR with approach docs for the following approaches:
-
Looping with modifying the parameter, with a normal arithmetic variant and a binary operation variant.
-
Looping without modifying the parameter, with a multiplying every loop variant and a [
range()with exponentiation variant]. -
Converting to a binary string, with a manual looping variant and a
sum()variant (and anothersum()variant). The approach doc will also mention that anf-stringcould be used instead ofbin(). -
The “cheating” way (with a warning that this isn’t the intended solution!), with an
int.bit_count()variant and astr.count()variant.
Approaches/variants that may or may not be worth adding:
-
An even more extreme variant of the “cheating” approach, using function aliasing.
-
An approach that converts to a binary string and uses regular expressions to count the ones. Regexes would definitely over-complicate things, but it might be an opportunity to show how regexes are not suitable for everything.
-
A variant of the binary modification variant that I can’t really understand. If I added this, I would need some help in understanding it.