From this forum thread.
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:
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.
New ideas (things that weren't on the forum post):
From this forum thread.
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.
New ideas (things that weren't on the forum post):
A
divmod()variant and alistvariant of the "looping with modifying the parameter" approach.A
len()variant and amap()variant of the "converting to a binary string" approach.A
range()withsum()variant for the "looping without modifying the parameter" approach.A recursive approach with a normal variant and a tail call variant.
Perhaps an approach with the task broken into multiple functions? All of them seem unnecessarily long and complicated, though, so maybe it's not worth it.