Created
June 15, 2020 16:20
-
-
Save yashbhutoria/733751bb4515e09aeca09b4a595ca583 to your computer and use it in GitHub Desktop.
Fizz Buzz solution using an approach similar to to Sieve of Eratosthenes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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