3 ms·
The lambda's purpose here is only to turn it into a one-liner. It can be rewritten as def fizzbuzz(n): num_map = { 1: n, 6: "Fizz", 10: "Buzz", 0:
by leblancfg 6y ago
The lambda's purpose here is only to turn it into a one-liner. It can be rewritten as
def fizzbuzz(n):
num_map = { 1: n, 6: "Fizz", 10: "Buzz", 0: "FizzBuzz" }
return num_map[n**4%15]
for i in range(100):
print(fizzbuzz(i + 1))
The real skill would be to demonstrate that you know/remember/can apply Euler's totient theorem off-the-cuff in an interview!
- omaranto 6y agoI don't know about Jane Street or Galois, but Renaissance is full of mathematicians so I doubt they'd be impressed by Euler's theorem. Math students learn it in undergrad, it is considered basic.
- roelschroeven 6y agoWe can even easily write it as a one-line without lambda: [{ 1: n, 6: "Fizz", 10: "Buzz", 0: "FizzBuzz" }[n**4%15] for n in range(1, 101)] The lambda in the original code is just used to convert the 0..99 that's generated by range(100) to 1..100. Using range(1, 101) instead generates the appropriate range of numbers from the beginning.