Skip to content

Instantly share code, notes, and snippets.

@sweetpalma
Created June 30, 2016 05:12
Show Gist options
  • Select an option

  • Save sweetpalma/cc7fbb78bd68faedfa182340ac5a21c2 to your computer and use it in GitHub Desktop.

Select an option

Save sweetpalma/cc7fbb78bd68faedfa182340ac5a21c2 to your computer and use it in GitHub Desktop.
Precalculated FizzBuzz in Python
# Obvious code:
N, F, B = False, 'Fizz', 'Buzz'
seq = [N, N, F, N, B, F, N, N, F, B, N, F, N, N, F + B]
[print(seq[x % 15 - 1] or x) for x in range(1, 101)]
# How does it work? Just take a look at sample output, see that rhytm?
# 1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
# 16 17 Fizz 19 Buzz Fizz 22 23 Fizz Buzz 26 Fizz 28 29 FizzBuzz
# 31 32 Fizz 34 ... ZZZZ
# And so on. It's being repeated each 15 steps. So I've just precalculated
# this sequence and used it my loop. Pretty easy, right?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment