-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfizzbuzz.py
More file actions
34 lines (25 loc) · 832 Bytes
/
fizzbuzz.py
File metadata and controls
34 lines (25 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from typing import Callable
from src.pipe import pipe
def fizzbuzz(input: list[int]) -> list[int | str]:
return pipe(
input,
_map(_fizzbuzz)
)
def _fizzbuzz(number: int) -> str:
return pipe(
number,
_carbonate(15, "FizzBuzz"),
_carbonate(3, "Fizz"),
_carbonate(5, "Buzz"),
_carbonate(1, str(number)) # <-- carbonateRemaining
)
def _carbonate(divisor: int, label: str) -> Callable[[int | str], int | str]:
def _partial(number: int | str) -> int | str:
if isinstance(number, str):
return number
return label if number % divisor == 0 else number
return _partial
def _map(f: Callable[[int], str]) -> Callable[[list], list]:
def _partial(input: list) -> list:
return list(map(f, input))
return _partial