TheAlgorithms / Python Public
master
Commits on Oct 29, 2021
-
Hexagonal number sequence (#5640)
* Hexagonal number sequence A hexagonal number sequence is a sequence of figurate numbers where the nth hexagonal number hₙ is the number of distinct dots in a pattern of dots consisting of the outlines of regular hexagons with sides up to n dots, when the hexagons are overlaid so that they share one vertex. This program returns the hexagonal number sequence of n length. * Update hexagonalnumbers.py * Update hexagonalnumbers.py * Update hexagonalnumbers.py * Update hexagonalnumbers.py * Update and rename hexagonalnumbers.py to hexagonal_numbers.py * Length must be a positive integer Co-authored-by: Christian Clauss <cclauss@me.com>
-
Delete other/date_to_weekday.py as a how-to-use, not an algorithm (#5591
) * [mypy] Fixes typing errors in other/date_to_weekday * [mypy] uses future annotation style for other/date_to_weekly * date_to_weekday: new implementation replaces buggy original * date_to_weekday: add examples from multiple of 100 years * clean-up: runs `black` to fix formatting * Delete date_to_weekday.py Co-authored-by: Christian Clauss <cclauss@me.com>
-
[mypy] Annotates other/scoring_algorithm (#5621)
* scoring_algorithm: Moves doctest into function docstring so it will be run * [mypy] annotates other/scoring_algorithm * [mypy] renames temp var to unique value to work around mypy issue in other/scoring_algorithm reusing loop variables with the same name and different types gives this very confusing mypy error response. pyright correctly infers the types without issue. ``` scoring_algorithm.py:58: error: Incompatible types in assignment (expression has type "float", variable has type "List[float]") scoring_algorithm.py:60: error: Unsupported operand types for - ("List[float]" and "float") scoring_algorithm.py:65: error: Incompatible types in assignment (expression has type "float", variable has type "List[float]") scoring_algorithm.py:67: error: Unsupported operand types for - ("List[float]" and "float") Found 4 errors in 1 file (checked 1 source file) ``` * scoring_algorithm: uses enumeration instead of manual indexing on loop var * scoring_algorithm: sometimes we look before we leap. * clean-up: runs `black` to fix formatting
Commits on Oct 28, 2021
-
[mypy] Fix type annotations in
wavelet_tree.py
(#5641)* [mypy] Fix type annotations for wavelet_tree.py * fix a typo
-
[mypy] Fix type annotation in euler_method.py (#5649)
* [mypy] Fix type annotation in euler_method.py In line with issue #4052. * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
-
Add solution for Project Euler problem 67 (#5519)
* New solution for Euler problem 67 A faster and memory efficient solution based on the template of sol1.py. Modified the solution to be more memory efficient while reading and generating the array and during the solution finding. No conditions and straightforward logic. * added return type hint * Update project_euler/problem_067/sol2.py Preferring comprehensions over map Co-authored-by: Christian Clauss <cclauss@me.com> * Update sol2.py Self explanatory variable names * Updated sol2 to problem 067 in directory * Update project_euler/problem_067/sol2.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update project_euler/problem_067/sol2.py Co-authored-by: Christian Clauss <cclauss@me.com> * Fixed extra line Co-authored-by: Christian Clauss <cclauss@me.com>
-
Add pyupgrade to pre-commit (#5638)
* Add pyupgrade to pre-commit * Remove unused imports * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
-
Implement Circular Queue using linked lists. Fixes #5361 (#5587)
* CircularQueueLinkedList: empty list, trivial implementation #5361 * CircularQueueLinkedList: single element list #5361 * CircularQueueLinkedList: refactor, no que empty attribute #5361 * CircularQueueLinkedList: refactor #5361 * CircularQueueLinkedList: changed internal data structure to use double linked list #5361 * CircularQueueLinkedList: enqueue test cases added #5361 * CircularQueueLinkedList: track full queue #5361 * CircularQueueLinkedList: adding functions description #5361 * CircularQueueLinkedList: type hints #5361 * CircularQueueLinkedList: algorithm explanation #5361 * CircularQueueLinkedList: missing type hints #5361 * CircularQueueLinkedList: more missing type hints #5361 * Update data_structures/queue/circular_queue_linked_list.py Co-authored-by: John Law <johnlaw.po@gmail.com>
-
[mypy] Fix type annotations for binary tree traversals in data struct…
…ures (#5556) * [mypy] Fix type annotations for binary tree traversals in data structures * Change variable name and update level_order_1 to use a deque Using a deque instead of a list here, because since we are removing from the beginning of the list, the deque will be more efficient. * remove duplicate function * Update data_structures/binary_tree/binary_tree_traversals.py Co-authored-by: John Law <johnlaw.po@gmail.com> * fix function name at line 137 * Update data_structures/binary_tree/binary_tree_traversals.py Co-authored-by: John Law <johnlaw.po@gmail.com> * Update data_structures/binary_tree/binary_tree_traversals.py Co-authored-by: John Law <johnlaw.po@gmail.com> * Remove type alias and use the new syntax * Update data_structures/binary_tree/binary_tree_traversals.py Co-authored-by: John Law <johnlaw.po@gmail.com> * Remove prints inside functions and return lists Co-authored-by: John Law <johnlaw.po@gmail.com>
Commits on Oct 27, 2021
-
Fix pull request template (#5633)
The existing template uses * to apply bold font weight. As we already have the ### to markdown the text as heading, its redundant to have the *s.
-
Add doctest for exception (#5629)
* Add doctest for exception * Spelling correction
-
Add Project Euler Problem 078 solution 01 (#5565)
* Create sol1.py * updating DIRECTORY.md * Create __init__.py * Add docstring * Reformat with black * Fix flake8 issues * Add EOL * Fix formatting issues * Add docstring * Add func return type * Change return type * Remove test print statement * Reformat code * Fix return types * Break loop * Update doctest sol * Update project_euler/problem_078/sol1.py Co-authored-by: John Law <johnlaw.po@gmail.com> * Added doctest and changed return type * Add int() * Fix flake8 issues * Use argument instead of fixed constant * Update sol1.py * fix sol1.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: John Law <johnlaw.po@gmail.com>
-
Rewrite parts of Vector and Matrix (#5362)
* Rewrite parts of Vector and Matrix methods * Refactor determinant method and add unit tests Refactor determinant method to create separate minor and cofactor methods. Add respective unit tests for new methods. Rename methods using snake case to follow Python naming conventions. * Reorganize Vector and Matrix methods * Update linear_algebra/README.md Co-authored-by: John Law <johnlaw.po@gmail.com> * Fix punctuation and wording * Apply suggestions from code review Co-authored-by: John Law <johnlaw.po@gmail.com> Co-authored-by: John Law <johnlaw.po@gmail.com>
-
Commits on Oct 26, 2021
-
Sphere intersection and spherical cap volumes (#5579)
* sphere intersection + spherical cap volume formulas * reformatted * Update volume.py Co-authored-by: Christian Clauss <cclauss@me.com>
-
[mypy] Fix type annotations for stack_using_dll.py (#5577)
* Fix mypy annotations for stack_using_dll.py * Replace Optional with inline union type
-
-
Added physical pressure units (#5613)
* Added physical pressure units This uses tuple pair which stores units required to be converted to respective other units as mentioned. Available Units:- Pascal,Bar,Kilopascal,Megapascal,psi(pound per square inch),inHg(in mercury column),torr,atm * Formatted file File was formatted as per repo rules * Reformatted file :) * Added more reference * More reference added
-
Add solution for probelm_686 of project_euler (#5480)
* Added solution for probelm_686 of project_euler * Changed documentation and formatting. * Added ref link to optimization logic * Update project_euler/problem_686/sol1.py Co-authored-by: John Law <johnlaw.po@gmail.com> Co-authored-by: John Law <johnlaw.po@gmail.com>
-
-
Financial: principle -> principal (#5614)
* Financial: principle -> principal The originally invested amount of money: `principal` -- https://www.grammarly.com/blog/principle-principal/ * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
-
* feat: creates math calculations for financials * refactor: make pull request items requirements * refactor: provides type hint for parameters * refactor: applies code review suggestions * refactor: adds more examples tests * refactor: throws ValueError instead of Exception * refactor: fix formatting * refactor: fix formatting * Update interest.py * Update and rename financials/ABOUT.md to financial/ABOUT.md * Rename financials/__init__.py to financial/__init__.py * Rename financials/interest.py to financial/interest.py * https://www.investopedia.com * Update __init__.py * pre-commit: Disable end-of-file-fixer * Revert change to pre-commit * Update __init__.py * __init__.py Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: John Law <johnlaw.po@gmail.com>
-
Added volume conversions (#5607)
* Added volume conversions This is a file which has relevant function which helps in conversion between volume units. Available Units:- Cubic metre,Litre,KiloLitre,Gallon,Cubic yard,Cubic foot,cup The file is also written in a way that , adding a new unit can easily be done by modifying tuple available in the source code * Formatted file The file was formatted to follow the syntax formatting rules of the repo * Formatted file further
-
Add decode function to base16.py (#5575)
* Add decode function * Update base16.py * Update base16.py * Update base16.py * Made the line shorter * Made another line shorter
-
* updating DIRECTORY.md * updating DIRECTORY.md * Create get_top_hn_posts.py * updating DIRECTORY.md * Add return type and desc * Add texttable * Update web_programming/get_top_hn_posts.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update web_programming/get_top_hn_posts.py Co-authored-by: Christian Clauss <cclauss@me.com> * Get top 10 posts * Update get_top_hn_posts.py * Don't use texttable * Setup doctest * Fix pre-commit issues * Remove print statement * Add hackernews_top_stories_as_markdown() Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
-
Fix validate_initial_digits of credit_card_validator.py (#5600)
* Fix validate_initial_digits of credit_card_validator.py @Bhargavishnu I think that I broke the logic of validate_initial_digits which should require that credit_card_number[0] is 3 before checking that credit_card_number[1] is 4, 5, or 7. Please verify the new changes and the new test cases to make sure that this is correct. Thanks! * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
-
[mypy] annotate
ciphers
(#5569)* [mypy] annotate `ciphers` * Update ciphers/polybius.py * Update polybius.py Co-authored-by: Christian Clauss <cclauss@me.com>
-
-
[mypy-fix] Type fixes for graham_scan (#5589)
* [mypy] Fixes type annotations in other/graham_scan #4052 + Prefer tuple to list for point x,y pairs * NOP: fixes typo in comment
-
* updating DIRECTORY.md * Create get_user_tweets.py * updating DIRECTORY.md * Reformat code with black * Add argument type * Add return type * Add tweepy * Fix isort issues * Fix flake8 issues * WIP: doctest * Doctest setup and format with pre-commit * Remove doctests * Update web_programming/get_user_tweets.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update get_user_tweets.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
-
add implementation of Nagel and Schrekenberg algo (#5584)
* add implementation of Nagel and Schrekenberg algo * Update cellular_automata/nasch.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update nasch.py * Update and rename nasch.py to nagel_schrekenberg.py * Update cellular_automata/nagel_schrekenberg.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update nagel_schrekenberg.py * Update nagel_schrekenberg.py * Update nagel_schrekenberg.py * update nagel_schrekenberg.py * Update nagel_schrekenberg.py Co-authored-by: Christian Clauss <cclauss@me.com>
-
Improved prime_numbers.py (#5592)
* Improved prime_numbers.py * update prime_numbers.py * Increase the timeit number to 1_000_000 Co-authored-by: Christian Clauss <cclauss@me.com>