-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- **Breaking:** Changed top level module name to `fizzbuzz`. Use `from fizzbuzz.fizzbuzzo3 import fizzbuzz` for rust implementation or `from fizzbuzz.fizzbuzzpy import fizzbuzz` for python implementation (slower). - Added typing and docstring hints available in IDE
- Loading branch information
1 parent
c8388dc
commit c132883
Showing
20 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[workspace] | ||
|
||
members = [ | ||
"fizzbuzz", | ||
"fizzbuzz-rust", | ||
"fizzbuzzo3" | ||
] | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.3.0 | ||
2.0.0 |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# ruff: noqa: PYI021 | ||
def fizzbuzz(n: int | list[int]) -> str: | ||
""" | ||
Compute the fizzbuzz answer for `n` using a highly efficient algorithm written in rust. | ||
The correct fizzbuzz answer is the original number, unless divisible by 3 or 5. | ||
For numbers divisible by 3, the correct answer is 'fizz'. | ||
For numbers divisible by 5, the correct answer is 'buzz'. | ||
For numbers divisible by both 3 & 5, the correct answer is 'fizzbuzz'. | ||
**Note:** Passing a `list` of values to fizzbuzz is more efficient than making multiple calls. | ||
Larger lists will be processed in parallel on multiple cpu cores. | ||
Arguments: | ||
n: either `int` the single number to fizzbuzz or `list[int]` a list of numbers to fizzbuzz. | ||
Returns: | ||
A string representing the fizzbuzz result. If `n` is an integer, the string contains the fizzbuzz | ||
answer for that number. If `n` is a list of integers, the string contains the fizzbuzz answers for each number, | ||
separated by commas and spaces (`, `). | ||
Examples: | ||
Using a single value: | ||
``` | ||
>>> from fizzbuzz.fizzbuzzo3 import fizzbuzz | ||
>>> fizzbuzz(1) | ||
'1' | ||
>>> fizzbuzz(5) | ||
'buzz' | ||
``` | ||
Using a list: | ||
``` | ||
>>> from fizzbuzz.fizzbuzzo3 import fizzbuzz | ||
>>> fizzbuzz([1, 5]) | ||
'1, buzz' | ||
``` | ||
""" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
Python 3.12.3 (main, Apr 17 2024, 00:00:00) [GCC 14.0.1 20240411 (Red Hat 14.0.1-0)] on linux | ||
Type "help", "copyright", "credits" or "license" for more information. | ||
>>> import fizzbuzz.fizzbuzzo3 as fb | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
ModuleNotFoundError: No module named 'fizzbuzz.fizzbuzzo3' | ||
>>> import fizzbuzz.fizzbuzzpy.fizzbuzzo3 as fb | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
ModuleNotFoundError: No module named 'fizzbuzz.fizzbuzzpy' | ||
>>> import fizzbuzzpy.fizzbuzzo3 as fb | ||
>>> fb.fizzbuzz.__doc__ | ||
>>> fb.fizzbuzz | ||
<built-in function fizzbuzz> | ||
>>> dict(fb.fizzbuzz) | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
TypeError: 'builtin_function_or_method' object is not iterable | ||
>>> fb.fizzbuzz.__dict__ | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
AttributeError: 'builtin_function_or_method' object has no attribute '__dict__'. Did you mean: '__dir__'? | ||
>>> fb.fizzbuzz.__dir__ | ||
<built-in method __dir__ of builtin_function_or_method object at 0x7fda6d9922f0> | ||
>>> fb.fizzbuzz.__dir__() | ||
['__repr__', '__hash__', '__call__', '__getattribute__', '__lt__', '__le__', '__eq__', '__ne__', '__gt__', '__ge__', '__reduce__', '__module__', '__doc__', '__name__', '__qualname__', '__self__', '__text_signature__', '__new__', '__str__', '__setattr__', '__delattr__', '__init__', '__reduce_ex__', '__getstate__', '__subclasshook__', '__init_subclass__', '__format__', '__sizeof__', '__dir__', '__class__'] | ||
>>> fb.fizzbuzz.__text_signature__() | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
TypeError: 'str' object is not callable | ||
>>> fb.fizzbuzz.__text_signature__ | ||
'(num)' | ||
>>> fb._dir__() | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
AttributeError: module 'fizzbuzzpy.fizzbuzzo3' has no attribute '_dir__' | ||
>>> import ast | ||
>>> dir(fb) | ||
['__all__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'fizzbuzz'] | ||
>>> type(fb.fizzbuzz) | ||
<class 'builtin_function_or_method'> | ||
>>> type(type(fb.fizzbuzz)) | ||
<class 'type'> | ||
>>> type(fb.fizzbuzz) == builtin_function_or_method | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
NameError: name 'builtin_function_or_method' is not defined | ||
>>> type(fb.fizzbuzz) == type('builtin_function_or_method') | ||
False | ||
>>> type(fb.fizzbuzz) == 'builtin_function_or_method' | ||
False | ||
>>> isinstance(fb.fizzbuzz, builtin_function_or_method) | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
NameError: name 'builtin_function_or_method' is not defined | ||
>>> import types.builtin_function_or_method | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
ModuleNotFoundError: No module named 'types.builtin_function_or_method'; 'types' is not a package | ||
>>> import types | ||
>>> isinstance(fb.fizzbuzz, types.builtin_function_or_method) | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
AttributeError: module 'types' has no attribute 'builtin_function_or_method' | ||
>>> isinstance(fb.fizzbuzz, types.BuiltinFunctionType) | ||
True | ||
>>> import types.BuiltinFunctionType as builtin | ||
Traceback (most recent call last): | ||
File "<stdin>", line 1, in <module> | ||
ModuleNotFoundError: No module named 'types.BuiltinFunctionType'; 'types' is not a package | ||
>>> |
File renamed without changes.
File renamed without changes.
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
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
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import pytest | ||
|
||
from fizzbuzzo3 import fizzbuzz | ||
from fizzbuzz.fizzbuzzo3 import fizzbuzz | ||
|
||
|
||
def test_lazy(): | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from fizzbuzzpy import fizzbuzz | ||
from fizzbuzz.fizzbuzzpy import fizzbuzz | ||
|
||
|
||
def test_lazy(): | ||
|