DEV Community

Discussion on: [Challenge] 🐝 FizzBuzz without if/else

Collapse
 
agtoever profile image
agtoever

A solution in Python. Feels silly though...

def fizzbuzz(n):
    offset = 0
    while n > 0:
        cycle = list(range(offset, 15 + offset))
        for i in range(3, 15, 3):
            cycle[i] = 'Fizz'
        for i in range(5, 15, 5):
            cycle[i] = 'Buzz'
        cycle.append('FizzBuzz')
        cycle.remove(offset)
        print('\n'.join(map(str, cycle[:min(15, n)])))
        offset += 15
        n -= 15


fizzbuzz(22)
Collapse
 
nombrekeff profile image
Keff

Wait until you see mine 😂