commit 4adf7f4f08f29a0fc0b380a42e2a03766049bfbb Author: Julien Palard Date: Thu Mar 14 09:15:38 2024 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4b0b98c --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +.venv/ +.envrc diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cebbece --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2024 Julien Palard + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/math_doodling/__init__.py b/math_doodling/__init__.py new file mode 100644 index 0000000..639a59a --- /dev/null +++ b/math_doodling/__init__.py @@ -0,0 +1,6 @@ +"""Just a demo module to play with math series.""" + +__version__ = "0.1" + +from math_doodling.public_api import fib +from math_doodling.exceptions import MyException diff --git a/math_doodling/__main__.py b/math_doodling/__main__.py new file mode 100644 index 0000000..f751639 --- /dev/null +++ b/math_doodling/__main__.py @@ -0,0 +1,18 @@ +from argparse import ArgumentParser +from un_paquet import fib + + +def parse_args(): + parser = ArgumentParser() + parser.add_argument("-v", help="Be verbose", action="store_true") + parser.add_argument("n", type=int) + return parser.parse_args() + + +def main(): + args = parse_args() + print(fib(args.n)) + +print(__name__) +if __name__ == "__main__": + main() diff --git a/math_doodling/exceptions.py b/math_doodling/exceptions.py new file mode 100644 index 0000000..b96c4aa --- /dev/null +++ b/math_doodling/exceptions.py @@ -0,0 +1,2 @@ +class MyException(Exception): + ... diff --git a/math_doodling/private_api.py b/math_doodling/private_api.py new file mode 100644 index 0000000..e69de29 diff --git a/math_doodling/public_api.py b/math_doodling/public_api.py new file mode 100644 index 0000000..963be49 --- /dev/null +++ b/math_doodling/public_api.py @@ -0,0 +1,8 @@ +from math_doodling.utils import cache + + +@cache(4096) +def fib(n): + if n < 2: + return 1 + return fib(n-1) + fib(n-2) diff --git a/math_doodling/utils.py b/math_doodling/utils.py new file mode 100644 index 0000000..ec90bde --- /dev/null +++ b/math_doodling/utils.py @@ -0,0 +1,12 @@ +def cache(limit): + def _cache(old_slow_function): + memory = {} + def new_faster_function(n): + if n in memory: + return memory[n] + result = old_slow_function(n) + if len(memory) < limit: + memory[n] = result + return result + return new_faster_function + return _cache diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..eae99bb --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "math_doodling" +authors = [{name = "Julien Palard", email = "julien@palard.fr"}] +license = {file = "LICENSE"} +classifiers = ["License :: OSI Approved :: MIT License"] +dynamic = ["version", "description"] + +[project.urls] +Home = "https://git.afpy.org/mdk/math_doodling"