looping through possible combinations of McNuggets packs of 6,9 and 20
Martin P. Hellwig
martin.hellwig at dcuktec.org
Fri Aug 13 06:51:22 EDT 2010
On 08/13/10 10:46, Peter Otten wrote:
> Martin P. Hellwig wrote:
>
>> SPOILER ALTER: THIS POST CONTAINS A POSSIBLE SOLUTION
No it wasn't :-)
> which should be 1*9 + 2*6
>
> What am I missing?
>
Aah interesting, 21 % 9 returns 3 instead of 12, which makes sense of
course. I guess the algorithm has to be adapted in a way that if the
value is bigger or equal twice the size of the modulo value you need to
iterate over it, something like:
for minus_multiplier in range(1, int(number, modulo_value)+2):
number = number - (modulo_value * minus_multiplier)
do the rest of the loop
Probably another ten lines or so to make it working as it should
--
mph
More information about the Python-list
mailing list