Skip to content

Instantly share code, notes, and snippets.

@yashbhutoria
Created June 15, 2020 16:20
Show Gist options
  • Save yashbhutoria/733751bb4515e09aeca09b4a595ca583 to your computer and use it in GitHub Desktop.
Save yashbhutoria/733751bb4515e09aeca09b4a595ca583 to your computer and use it in GitHub Desktop.
Fizz Buzz solution using an approach similar to to Sieve of Eratosthenes
def mark_multiples(ls, num, marker):
for i in range(num, len(ls), num):
ls[i] = marker if isinstance(ls[i], int) else (ls[i] + marker)
def main():
size = 100
nums = list(range(size+1))
mark_multiples(nums, 3, "Fizz")
mark_multiples(nums, 5, "Buzz")
[print(num) for num in nums[1:]]
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment