Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Late to the party but here's a solution I worked out using roots of unity and cosines:

  from math import cos, pi
  for n in range(1, 101):
      print([n, 'Fizz', 'Buzz', 'FizzBuzz'][round((1 + 2 * cos(2 * pi * n / 3)) / 3 + 2 * (1 + 2 * cos(2 * pi * n / 5) + 2 * cos(4 * pi * n / 5)) / 5)])


As it should be.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: