{"id":18885345,"url":"https://github.com/sir-gon/algorithm-exercises-py","last_synced_at":"2025-04-14T21:30:56.649Z","repository":{"id":58098724,"uuid":"529348780","full_name":"sir-gon/algorithm-exercises-py","owner":"sir-gon","description":"Algorithms Exercises solved in Python 3, running with built-in unittest suit. Developed with TDD.","archived":false,"fork":false,"pushed_at":"2024-10-29T22:47:59.000Z","size":1233,"stargazers_count":2,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-30T00:47:24.107Z","etag":null,"topics":["algorithm-exercises","algorithms","algorithms-and-data-structures","algorithms-and-datastructures","algorithms-datastructures","exercises-code-python","exercises-solutions","hackerrank","hackerrank-challenges","hackerrank-python","hackerrank-solutions","python","tdd","test-driven-development","test-driven-development-with-python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sir-gon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["sir-gon"],"buy_me_a_coffee":"gonzalodiaz"}},"created_at":"2022-08-26T17:29:29.000Z","updated_at":"2024-10-29T22:47:59.000Z","dependencies_parsed_at":"2023-09-27T00:28:54.633Z","dependency_job_id":"e8d41c86-b9e8-41db-9bb5-de99015364cb","html_url":"https://github.com/sir-gon/algorithm-exercises-py","commit_stats":null,"previous_names":["sir-gon/algorithm-exercises-py"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sir-gon%2Falgorithm-exercises-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sir-gon%2Falgorithm-exercises-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sir-gon%2Falgorithm-exercises-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sir-gon%2Falgorithm-exercises-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sir-gon","download_url":"https://codeload.github.com/sir-gon/algorithm-exercises-py/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223644768,"owners_count":17178797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithm-exercises","algorithms","algorithms-and-data-structures","algorithms-and-datastructures","algorithms-datastructures","exercises-code-python","exercises-solutions","hackerrank","hackerrank-challenges","hackerrank-python","hackerrank-solutions","python","tdd","test-driven-development","test-driven-development-with-python"],"created_at":"2024-11-08T07:18:00.761Z","updated_at":"2024-11-08T07:18:01.326Z","avatar_url":"https://github.com/sir-gon.png","language":"Python","readme":"# Algorithm Exercises (Python 3)\n\n[![Python CI](https://github.com/sir-gon/algorithm-exercises-py/actions/workflows/python.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-py/actions/workflows/python.yml)\n[![Markdown Lint](https://github.com/sir-gon/algorithm-exercises-py/actions/workflows/markdown-lint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-py/actions/workflows/markdown-lint.yml)\n[![YAML lint](https://github.com/sir-gon/algorithm-exercises-py/actions/workflows/yamllint.yml/badge.svg)](https://github.com/sir-gon/algorithm-exercises-py/actions/workflows/yamllint.yml)\n\n![GitHub](https://img.shields.io/github/license/sir-gon/algorithm-exercises-py)\n![GitHub language count](https://img.shields.io/github/languages/count/sir-gon/algorithm-exercises-py)\n![GitHub top language](https://img.shields.io/github/languages/top/sir-gon/algorithm-exercises-py)\n[![CodeFactor](https://www.codefactor.io/repository/github/sir-gon/algorithm-exercises-py/badge)](https://www.codefactor.io/repository/github/sir-gon/algorithm-exercises-py)\n[![codecov](https://codecov.io/gh/sir-gon/algorithm-exercises-py/branch/main/graph/badge.svg?token=U3N3HSC3YC)](https://codecov.io/gh/sir-gon/algorithm-exercises-py)\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fsir-gon%2Fprojecteuler-py.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fsir-gon%2Fprojecteuler-py?ref=badge_shield)\n[![OpenSSF Best Practices](https://www.bestpractices.dev/projects/6404/badge)](https://www.bestpractices.dev/projects/6404)\n\n[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-py\u0026metric=alert_status)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-py)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-py\u0026metric=coverage)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-py)\n[![Bugs](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-py\u0026metric=bugs)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-py)\n[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-py\u0026metric=code_smells)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-py)\n[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=sir-gon_algorithm-exercises-py\u0026metric=duplicated_lines_density)](https://sonarcloud.io/summary/new_code?id=sir-gon_algorithm-exercises-py)\n\n## TL;DR\n\nAlgorithms Exercises solved in [Python 3.x](https://www.python.org/),\nrunning with built-in unittest suit. Developed with TDD.\n\n[![Python](https://img.shields.io/badge/Python-3776AB?style=for-the-badge\u0026logo=python\u0026logoColor=white)](https://www.python.org/)\n[![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge\u0026logo=docker\u0026logoColor=white)](https://www.docker.com/)\n\nGo to [Install and run](#install-and-run)\n\n## What is this?\n\nThis repository is part of a series that share and solve the same [objectives](#objetives),\nwith the difference that each one is based on a different software ecosystem,\ndepending on the chosen programming language:\n\n- [Modern Javascript: algorithm-exercises-js](https://github.com/sir-gon/algorithm-exercises-js)\n- [Typescript: algorithm-exercises-ts](https://github.com/sir-gon/algorithm-exercises-ts)\n\n- [Python 3.x: algorithm-exercises-py](https://github.com/sir-gon/algorithm-exercises-py)\n- [Go / Golang: algorithm-exercises-go](https://github.com/sir-gon/algorithm-exercises-go)\n\n- [Java: algorithm-exercises-java](https://github.com/sir-gon/algorithm-exercises-java)\n- [.NET / C#: algorithm-exercises-csharp](https://github.com/sir-gon/algorithm-exercises-csharp)\n- [C++17: algorithm-exercises-cpp](https://github.com/sir-gon/algorithm-exercises-cpp)\n\n## Objetives\n\n### Functional\n\n- For academic purposes, it is an backup of some algorithm exercises\n(with their solutions), proposed by various sources:\n[leetcode, hackerrank, projecteuler](#algorithm-excersices-sources), ...\n\n- The solutions must be written on \"vanilla code\", that is,\navoiding as much as possible the use of external libraries (in runtime).\n\n- Adoption of methodology and good practices.\nEach exercise is implemented as a unit test set,\nusing TDD (Test-driven Development) and Clean Code ideas.\n\n### Technical\n\nFoundation of a project that supports:\n\n- Explicit **typing** when the language supports it, even when it is not mandatory.\n- Static Code Analysis (**Lint**) of code, scripts and documentation.\n- Uniform **Code Styling**.\n- **Unit Test** framework.\n- **Coverge** collection. High coverage percentage. Equal or close to 100%.\n- **Pipeline** (Github Actions). Each command must take care of its\nreturn status code.\n- **Docker**-based workflow to replicate behavior in any environment.\n- Other tools to support the reinforcement of software development **good practices**.\n\n## Install and Run\n\nYou can run tests in the following ways:\n\n- [Install and run directly](#install-and-run-directly) require runtime tools\ninstalled in your SO.\n- [Install and run with make](#install-and-run-using-make) require runtime tools\nand \"make\" installed in your SO.\n- [Install and in Docker](#install-and-running-with-docker-) require Docker and\ndocker-compose installed.\n- (⭐️)\n[Install and in Docker with make](#install-and-running-with-docker--using-make)\nrequire docker-compose and make installed.\n\n⭐️: Prefered way.\n\n### Install and Run directly\n\nUsing a Python 3.x runtime in your SO.\n\nFirst, load virtual env environment:\n\n```bash\nsource .venv/bin/activate\n```\n\nYou must install dependencies:\n\n```bash\npip3 install -r requirements.txt\n```\n\nEvery problem is a function with unit test.\n\nUnit test has test cases and input data to solve the problem.\n\nRun all tests collectino coverage:\n\n```bash\npython3 -m coverage run -m pytest --verbose src/\n```\n\n#### Test run with alternative behaviors\n\nYou can change test running behaviour using some environment variables as follows:\n\n| Variable | Values | Default |\n| ------ | ------ | ------ |\n| LOG_LEVEL  | `debug`, `warning`, `error`, `info` | `info` |\n| BRUTEFORCE | `true`, `false`| `false` |\n\n- `LOG_LEVEL`: change verbosity level in outputs.\n- `BRUTEFORCE`: enable or disable running large tests.\n(long time, large amount of data, high memory consumition).\n\n#### Examples running tests with alternative behaviors\n\nLog level in pytest require to pass a parameter.\nSo, to pass it in a similar way as another sibling stacks,\nthe following example is proposed to run tests with debug outputs:\n\n```bash\nLOG_LEVEL=debug python3 -m coverage run -m \\\n  pytest --verbose \\\n  -o log_cli=true \\\n  --log-cli-level=${LOG_LEVEL} \\\n  --full-trace src/\n```\n\nRun brute-force tests with debug outputs:\n\n```bash\nBRUTEFORCE=true LOG_LEVEL=debug python3 -m coverage run -m \\\n  pytest --verbose \\\n  -o log_cli=true \\\n  --log-cli-level=${LOG_LEVEL} \\\n  --full-trace src/\n```\n\n### Install and Run using make\n\n`make` tool is used to standardizes the commands for the same tasks\nacross each sibling repository.\n\nRun tests (libraries are installed as dependency task in make):\n\n```bash\nmake test\n```\n\nRun tests with debug outputs:\n\n```bash\nmake test -e LOG_LEVEL=debug\n```\n\nRun brute-force tests with debug outputs:\n\n```bash\nmake test -e BRUTEFORCE=true -e LOG_LEVEL=debug\n```\n\nAlternative way, use environment variables as prefix:\n\n```bash\nBRUTEFORCE=true LOG_LEVEL=debug make test\n```\n\n### Install and Running with Docker 🐳\n\nBuild an image of the test stage.\nThen creates and ephemeral container an run tests.\n\nBRUTEFORCE and LOG_LEVEL environment variables are passing from current\nenvironment using docker-compose.\n\n```bash\ndocker-compose --profile testing run --rm algorithm-exercises-py-test\n```\n\nTo change behavior using environment variables, you can pass to containers\nin the following ways:\n\nFrom host using docker-compose (compose.yaml) mechanism:\n\n```bash\nBRUTEFORCE=true LOG_LEVEL=debug docker-compose --profile testing run --rm algorithm-exercises-py-test\n```\n\nOverriding docker CMD, as parameter of make \"-e\":\n\n```bash\ndocker-compose --profile testing run --rm algorithm-exercises-py-test make test -e LOG_LEVEL=DEBUG -e BRUTEFORCE=true\n```\n\n### Install and Running with Docker 🐳 using make\n\n```bash\nmake compose/build\nmake compose/test\n```\n\nTo pass environment variables you can use docker-compose\nor overriding CMD and passing to make as \"-e\" argument.\n\nPassing environment variables using docker-compose (compose.yaml mechanism):\n\n```bash\nBRUTEFORCE=true LOG_LEVEL=debug make compose/test\n```\n\n## Development workflow using Docker / docker-compose\n\nRunning container with development target.\nDesigned for development workflow on top of this image.\nAll source application is mounted as a volume in **/app** directory.\nDependencies should be installed to run so, you must\ninstall dependencies before run (or after a dependency add/change).\n\n```bash\n# Build development target image\ndocker-compose build --compress algorithm-exercises-py-dev\n\n# Run ephemeral container and override CMD to run test\ndocker-compose run --rm algorithm-exercises-py-dev python3 -m coverage run -m pytest --verbose src/\n```\n\n## Run complete workflow (Docker + make)\n\nFollowing command simulates a standarized pipeline across environments,\nusing docker-compose and make.\n\n```bash\nmake compose/build \u0026\u0026 make compose/lint \u0026\u0026 make compose/test \u0026\u0026 make compose/run\n```\n\n- Build all Docker stages and tag relevant images.\n- Run static analysis (lint) checks\n- Run unit tests\n- Run a \"final\" production ready image as a final container.\nFinal \"production\" image just shows a minimal \"production ready\"\nbuild (with no tests).\n\n## About development\n\nDeveloped with runtime:\n\n```text\npython3 --version\nPython 3.12.3\n```\n\n## Algorithm excersices sources\n\n- [Leetcode](https://leetcode.com/) online platform for\ncoding interview preparation.\n- [HackerRank](https://www.hackerrank.com/) competitive programming challenges\nfor both consumers and businesses.\n- [Project Euler](https://projecteuler.net/) a series of computational problems\nintended to be solved with computer programs.\n\nUse these answers to learn some tip and tricks for algorithms tests.\n\n### Disclaimer. Why I publish solutions?\n\nAs Project Euler says:\n\n\u003chttps://projecteuler.net/about#publish\u003e\n\n```text\nI learned so much solving problem XXX, so is it okay to publish my solution elsewhere?\nIt appears that you have answered your own question. There is nothing quite like that \"Aha!\" moment when you finally beat a problem which you have been working on for some time. It is often through the best of intentions in wishing to share our insights so that others can enjoy that moment too. Sadly, that will rarely be the case for your readers. Real learning is an active process and seeing how it is done is a long way from experiencing that epiphany of discovery. Please do not deny others what you have so richly valued yourself.\n\nHowever, the rule about sharing solutions outside of Project Euler does not apply to the first one-hundred problems, as long as any discussion clearly aims to instruct methods, not just provide answers, and does not directly threaten to undermine the enjoyment of solving later problems. Problems 1 to 100 provide a wealth of helpful introductory teaching material and if you are able to respect our requirements, then we give permission for those problems and their solutions to be discussed elsewhere.\n```\n\nIf you have better answers or optimal solutions, fork and PR-me\n\nEnjoy 😁 !\n\n## Status\n\n### License\n\n[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fsir-gon%2Fprojecteuler-py.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fsir-gon%2Fprojecteuler-py?ref=badge_large)\n\n### Coverage\n\n[![Coverage](https://codecov.io/gh/sir-gon/algorithm-exercises-py/branch/main/graphs/tree.svg?token=VMH4I0MDFR)](https://app.codecov.io/gh/sir-gon/algorithm-exercises-py)\n","funding_links":["https://github.com/sponsors/sir-gon","https://buymeacoffee.com/gonzalodiaz"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsir-gon%2Falgorithm-exercises-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsir-gon%2Falgorithm-exercises-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsir-gon%2Falgorithm-exercises-py/lists"}