Created
April 8, 2021 11:37
-
-
Save tokdaniel/d4950be033ffd81054014fe3502304f2 to your computer and use it in GitHub Desktop.
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
from functools import reduce | |
def compose2(f, g): | |
return lambda *a, **kw: f(g(*a, **kw)) | |
def compose(*fs): | |
return reduce(compose2, fs) | |
def safeMod(input, divider): | |
return input % divider if type(input) == int else input | |
def is_divisible_by(divisor): | |
return (lambda replacer: (lambda value: replacer if safeMod(value, divisor) == 0 else value)) | |
fizz = is_divisible_by(3)("Fizz") | |
buzz = is_divisible_by(5)("Buzz") | |
fizz_buzz = is_divisible_by(15)("FizzBuzz") | |
fizz_buzzer = compose(fizz, buzz, fizz_buzz) | |
result = map(fizz_buzzer, range(1, 100)) | |
for i in result: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment