* Update queue implementation
Popping the first element of a list takes O(n) time.
Using a cyclic queue takes O(1) time.
* Add queue changes from extra files
* Update indentation
* Add empty line between imports
* Fix lines
* Apply suggestions from code review
Co-authored-by: John Law <johnlaw.po@gmail.com>
Co-authored-by: John Law <johnlaw.po@gmail.com>
* 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>
* [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>
* 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
* [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>
* 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>
* [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>
* 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>
* 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
* 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
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>
* 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
* 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>