3 ms·
Right, but your comment doesn't do justice to the beauty of the solution being so concise. Is it a coincidence that the same exponent 4 works for both multiples
by chronolitus 6y ago
Right, but your comment doesn't do justice to the beauty of the solution being so concise. Is it a coincidence that the same exponent 4 works for both multiples of 3 and 5?
What if instead of 3 and 5, we did FizzBuzz with 7 and 11?
Let's do n%77, now we need to map 7, 14, 21, 28, 35, 42, 49, 56, 63, 70 to Fizz, and 11, 22, 33, 44, 55, 66 to Buzz, unless we can find some way to have them all reduce to the same number. Is that really so straightforward?
Now that we know the trick with the exponents, we could try a few to start.
For multiples of 11 it seems the smallest one which works is 6! Great, let's try it on multiples of 7.. Nope.
Ok, for multiples of 7, I see that ^10 works.. but that doesn't work for multiples of 11.
* the article addresses this at the end, and tells us that the correct exponent is ^30, the lowest common denominator of 6 and 10. But if I'd been given this problem, I'd have remained stuck on the second paragraph of this comment, with no idea where to start when seeking to reduce the divisors to a single number.
- namelessUser 6y agoIf a^n = 0 (or 1) mod b, then a^(kn) = (a^n)^k = 0 (or 1) mod b for any positive integer k. Therefore you need to pick a common multiple of 6 and 10.