2019-11-30 11:36:58 +01:00
|
|
|
#! /usr/bin/env python
|
2019-11-30 12:04:57 +01:00
|
|
|
from typing import Callable, Dict
|
|
|
|
|
|
|
|
|
|
|
|
def fizzbuzzer(words: Dict[int, str]) -> Callable[[int], None]:
|
|
|
|
def _fun(max: int) -> None:
|
|
|
|
for i in range(1, max + 1):
|
|
|
|
out = []
|
2019-11-30 12:08:18 +01:00
|
|
|
for div, word in sorted(words.items()):
|
2019-11-30 12:04:57 +01:00
|
|
|
if i % div == 0:
|
|
|
|
out.append(word)
|
|
|
|
if len(out) > 0:
|
|
|
|
print("".join(out))
|
|
|
|
else:
|
|
|
|
print(i)
|
|
|
|
|
|
|
|
return _fun
|
2019-11-30 11:36:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
def fizzbuzz(max: int = 100) -> None:
|
2019-11-30 11:53:54 +01:00
|
|
|
words = {
|
|
|
|
3: "fizz",
|
|
|
|
5: "buzz",
|
|
|
|
}
|
2019-11-30 12:04:57 +01:00
|
|
|
f = fizzbuzzer(words)
|
|
|
|
f(max)
|
2019-11-30 11:36:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
fizzbuzz()
|