3 ms·
I would do this: Let i = ((n % 3) == 0) | ((n % 5) == 0) << 1 Then map output as { n, 'Fizz', 'Buzz', 'FizzBuzz' }
by johbjo 6y ago
I would do this:
Let i = ((n % 3) == 0) | ((n % 5) == 0) << 1
Then map output as { n, 'Fizz', 'Buzz', 'FizzBuzz' }
- MauranKilom 6y agoOr, using only elementary math: Let i = ((n % 3) ** 2) + ((n % 5) ** 4) * 2 Or, given any number n of primes p_j, the "fizzbuzz index" i is just Let i = sum_over_j(((n % p_j) ** (p_j - 1)) * (n ** j)) (This doesn't generalize to non-primes via the totient function for the same reason the post's solution doesn't generalize - (a % k) * phi(k) for prime k is zero if and only if k divides a, but for non-prime k it can also become zero for other a.)