Commit Graph

137 Commits

Author SHA1 Message Date
Vardhaman
2d5dd6f132
MAINT: Updated f-string method (#6230)
* MAINT: Used f-string method

Updated the code with f-string methods wherever required for a better and cleaner understanding of the code.

* Updated files with f-string method

* Update rsa_key_generator.py

* Update rsa_key_generator.py

* Update elgamal_key_generator.py

* Update lru_cache.py

I don't think this change is efficient but it might tackle the error as the error was due to using long character lines.

* Update lru_cache.py

* Update lru_cache.py

Co-authored-by: cyai <seriesscar@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-07-07 16:34:07 +02:00
Goodness Ezeh
f4a16f607b
Lowercase g --> Capital G (#5845)
* Updated the comments in the code

* Update .gitignore

* Update .gitignore

* Update .gitignore

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-11-24 15:23:44 +01:00
Andrew Grangaard
551c65766d
[Mypy] fix other/least_recently_used (#5814)
* makes LRUCache constructor concrete

* fixes bug in dq_removal in other/least_recently_used

+ deque.remove() operates by value not index

* [mypy] Annotates other/least_recently_used over generic type

+ clean-up: rename key_reference to match type.

* [mypy] updates example to demonstrate LRUCache with complex type

* Adds doctest to other/least_recently_used

* mypy.ini: Remove exclude = (other/least_recently_used.py)

* Various mypy configs

* Delete mypy.ini

* Add mypy to .pre-commit-config.yaml

* mypy --ignore-missing-imports --install-types --non-interactive .

* mypy v0.910

* Pillow=8.3.7

* Pillow==8.3.7

* Pillow==8.3.2

* Update .pre-commit-config.yaml

* Update requirements.txt

* Update pre-commit.yml

* --install-types  # See mirrors-mypy README.md

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-11-16 15:01:17 +01:00
Andrew Grangaard
f36ee034f1
[mypy] Annotate other/lru_cache and other/lfu_cache (#5755)
* Adds repr and doctest of current behavior linkedlist in other/lru_cache

* Blocks removal of head or tail of double linked list

* clarifies add() logic for double linked list in other/lru_cache

* expands doctests to compare cache and lru cache

* [mypy] annotates vars for other/lru_cache

* [mypy] Annotates lru_cache decorator for other/lru_cache

* Higher order functions require a verbose Callable annotation

* [mypy] Makes LRU_Cache generic over key and value types for other/lru_cache

+ no reason to force int -> int

* [mypy] makes decorator a classmethod for access to class generic types

* breaks two long lines in doctest for other/lru_cache

* simplifies boundary test remove() for other/lru_cache

* [mypy] Annotates, adds doctests, and makes Generic other/lfu_cache

See also commits to other/lru_cache which guided these

* [mypy] annotates cls var in other/lfu_cache

* cleans up items from code review for lfu_cache and lru_cache

* [mypy] runs mypy on lfu_cache and lru_cache
2021-11-10 23:21:16 +01:00
Joyce
7e81551d7b
[mypy] fix type annotations for other/least-recently-used.py (#5811) 2021-11-10 20:55:23 +01:00
Rohan R Bharadwaj
accee50cde
[mypy] Fix other/fischer_yates_shuffle.py (#5789)
* [mypy] Fix `other/fischer_yates_shuffle.py`

* Update mypy.ini
2021-11-07 11:14:42 +01:00
Andrew Grangaard
7954a3ae16
[mypy] Fixes typing errors in other/dpll (#5759)
+ As per usage examples, clause literals are a list of strings.
  + Note: symbols extracted from literals are expected to be exactly two characters.
+ self.literal boolean values are initialized to None, so must be optional
+ model values should be Booleans, but aren't guaranteed to be non-None
  in the code.
+ uses newer '... | None' annotation for Optional values
+ clauses are passed to the Formula initializer as both lists and sets, they
  are stored as lists.  Returned clauses will always be lists.
+ use explicit tuple annotation from __future__  rather than using (..., ...)
  in return signatures
+ mapping returned by dpll_algorithm is optional per the documentation.
2021-11-03 21:32:49 +01:00
SURYAPRATAP SINGH SURYAVANSHI
13fdf21c9c
Added alternative_list_arrange method (#4631) 2021-10-31 11:40:32 +01:00
Andrew Grangaard
a281151a2c
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>
2021-10-29 09:22:57 +02:00
Andrew Grangaard
0fc24e8629
[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
2021-10-29 13:21:16 +08:00
Andrew Grangaard
de07245c17
[mypy] Adds type annotations in other/activity_selection #4052 (#5590) 2021-10-26 12:10:37 +02:00
Andrew Grangaard
2606f1bbe5
[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
2021-10-26 11:50:36 +02:00
Snimerjot Singh
c886a66d34
Added check_strong_password.py (#4950)
* Added check_strong_password.py

* Corrected Comment

* Updated

* Updated check_strong_password.py

* Ran Pre-Commit
2021-10-20 07:35:41 +02:00
Christian Clauss
cecf43d648
Pyupgrade to Python 3.9 (#4718)
* Pyupgrade to Python 3.9

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-09-07 13:37:03 +02:00
Christian Clauss
ef9827166e
Approve functions used as default arguments (#4699)
* Approve functions used as default argumenets

* The default value for **seed** is the result of a function call

The default value for **seed** is the result of a function call which is not normally recommended and causes flake8-bugbear to raise a B008 error. However, in this case, it is accptable because `LinearCongruentialGenerator.__init__()` will only be called once per instance and it ensures that each instance will generate a unique sequence of numbers.

* The default value for **backend** is the result of a function call

The default value for **backend** is the result of a function call which is not normally recommended and causes flake8-bugbear to raise a B008 error. However, in this case, it is accptable because `Aer.get_backend()` is called when the function is definition and that same backend is then reused for function calls.

* Update linear_congruential_generator.py

* Update ripple_adder_classic.py

* Update ripple_adder_classic.py

* Update ripple_adder_classic.py

* Update ripple_adder_classic.py

* Update ripple_adder_classic.py
2021-08-31 07:56:19 +02:00
arfy slowy
8e5c3536c7
[fixed] unused variable, standalone running, import doctest module (#4673)
* [fixed] unused variable, standalone running, import doctest module

information [standalone running](https://www.geeksforgeeks.org/what-does-the-if-__name__-__main__-do/)

Signed-off-by: slowy07 <slowy.arfy@gmail.com>

* Update other/fischer_yates_shuffle.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* [fixed] change to tuple and fixing callfunction

Signed-off-by: slowy07 <slowy.arfy@gmail.com>

* Update matrix/spiral_print.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update matrix/spiral_print.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* fixing

Co-authored-by: Christian Clauss <cclauss@me.com>

* [fixed] sprial matrix

Signed-off-by: slowy07 <slowy.arfy@gmail.com>

* Update spiral_print.py

* Update spiral_print.py

* Update spiral_print.py

* Update spiral_print.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-08-28 20:07:10 +02:00
SURYAPRATAP SINGH SURYAVANSHI
9cb5760e89
add date_to_weekday finder method (#4599)
* add date_to_weekday finder method

* reformat date_to_weekday method

* remove time

* remove hardcode weekdays list

* fix return type error

* fixing fail issue

* Finding the test failing issue

* after testing the pre-commit in local environment
2021-08-18 14:05:41 +02:00
Dhruv Manilawala
6f21f76696
fix(ci): Update pre-commit hooks and apply new black (#4359)
* fix(ci): Update pre-commit hooks and apply new black

* remove empty docstring
2021-04-26 07:46:50 +02:00
Christian Clauss
ba974810d6
Simplify password_generator() (#4333) 2021-04-22 14:22:54 +05:30
algobytewise
0ee8f792e3
Moved "other/anagrams.py" to the string folder (#4289)
* move&rename, changed code accordingly

* adjusted codespell ignore-list
2021-03-22 11:40:23 +01:00
algobytewise
ce99859ad5
Move files to various folders (#4286)
* Move files to cellular_automata

* Rename other/davis–putnam–logemann–loveland.py to backtracking/davis–putnam–logemann–loveland.py

* Rename other/markov_chain.py to graphs/markov_chain.py

* undid rename: need to fix mypy first
2021-03-22 10:54:04 +01:00
algobytewise
8d51c2cfd9
move-files-and-2-renames (#4285) 2021-03-22 10:52:26 +01:00
algobytewise
99a42f2b58
Move files to strings folder (#4283)
* Move files to strings-folder

* moved the file "words" back to the original folder

* moved "anagram.py" also back

* fix the codespell ignore-list
2021-03-21 12:05:10 +01:00
algobytewise
8f5f32bc00
New fractals folder (#4277)
* reupload

* delete file

* Move koch_snowflake.py to fractals-folder

* Move mandelbrot.py to fractals-folder

* Move sierpinski_triangle.py to fractals-folder
2021-03-20 06:49:30 +01:00
ulwlu
a796ccf1ce
Add graham scan algorithm (#4205)
* Add graham scan algorithm

* Fix argument name p with point

* Add tests in inner function

* updating DIRECTORY.md

* Fix graham scan for isort --profile=black

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-03-02 13:24:41 +01:00
Shivanirudh
eab6b70e0a
DPLL algorithm (#3866)
* DPLL algorithm

* Corrections complete

* Formatting

* Codespell hook

* Corrections part 2

* Corrections v2

* Corrections v3

* Update and rename dpll.py to davis–putnam–logemann–loveland.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-11-08 18:26:22 +01:00
Shabab Karim
95db17ce0f
Added two pointer solution for two sum problem (#3468) 2020-10-26 11:08:53 +01:00
anneCoder1805
74233022a0
Median of Two Arrays (#3554)
* Create medianOf TwoArrays.py

This code finds the median of two arrays (which may or may not be sorted initially).
Example: 
Enter elements of an array: 1 5 4 2
Enter elements of another array: 1 7 4 2 7
The median of two arrays is :  4

* Rename medianOf TwoArrays.py to median_of _two_arrays.py

* Rename median_of _two_arrays.py to median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py

* Update median_of_two_arrays.py
2020-10-20 12:38:49 +02:00
Kushagra Bansal
ec9f6b6467
Created max_sum_sliding_window in Python/other (#3065)
* Add files via upload

* Update max_sum_sliding_window.py

* Update max_sum_sliding_window.py

* Update max_sum_sliding_window.py

* Added more tests

* Update max_sum_sliding_window.py

* Update max_sum_sliding_window.py
2020-10-09 17:51:04 +05:30
Ron U
c510a7da7b
Add doomsday algorithm (#2903)
* Added doomsday algorithm

* Adding unit-tests to doomsday algorithm

* running black on doomsday

* adding doctest and fixing a black issue [doomsday]

* Update doomsday.py

* fixing black issue [doomsday]

* Update other/doomsday.py

* Update doomsday.py

* adding more doctests (following review comment) [doomsday]

Co-authored-by: John Law <johnlaw.po@gmail.com>
2020-10-07 20:22:56 +08:00
Dhruv
48357cea5b
Add __init__.py files in all the directories (#2503) 2020-09-28 19:42:36 +02:00
spamegg
5f9be0a613
Add Python type hints and doctests to other/two_sum.py (#2467)
* Add Python type hints and doctests to other/two_sum.py

#2465

* Update other/two_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update other/two_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update two_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-09-23 21:55:51 +02:00
Christian Clauss
9200a2e543
from __future__ import annotations (#2464)
* from __future__ import annotations

* fixup! from __future__ import annotations

* fixup! from __future__ import annotations

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-09-23 13:30:13 +02:00
Hasenn
20e98fcded
Fix some warnings from LGTM (#2420)
* fix assignment of a variable to itself

* Fix unnecessary 'else' clause in loop

* formatting and redundant reasignment fix

* mark unreachable code with a TODO comment

* fix variable defined multiple times

* fix static method without static decorator

* revert unintended autoformatting

Co-authored-by: Christian Clauss <cclauss@me.com>

* revert autoformatting issue

* applied black autoformatting

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-09-13 10:11:27 +02:00
Du Yuanchao
4d0a8f2355
Optimized recursive_bubble_sort (#2410)
* optimized recursive_bubble_sort

* Fixed doctest error due whitespace

* reduce loop times for optimization

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-09-10 10:31:26 +02:00
NEERAJ ADITYANANTH POLAMPALLI
c0dcc556b3
Update triplet_sum.py (#2404) 2020-09-06 10:40:46 +02:00
Kushagra Bansal
5ef784331e
Created triplet_sum in Python/other (#2362)
* Add files via upload

* Update triplet_sum.py

* Update triplet_sum.py

* Update other/triplet_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update other/triplet_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update other/triplet_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update other/triplet_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update triplet_sum.py

* Update other/triplet_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update other/triplet_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update other/triplet_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update other/triplet_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

* Update other/triplet_sum.py

Co-authored-by: Christian Clauss <cclauss@me.com>

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-08-28 15:50:35 +02:00
Christian Clauss
1fb1fdd130
requirements.txt: Unpin numpy (#2287)
* requirements.txt: Unpin numpy

* fixup! Format Python code with psf/black push

* Less clutter

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-08-06 17:50:23 +02:00
Mark
a891f6802a
Procentual proximity scoring algorithm implemented (#2280)
* Procentual proximity scoring algorithm implemented

- added requested changes
- passed doctest

- passed flake8 test

* Apply suggestions from code review

Co-authored-by: Christian Clauss <cclauss@me.com>

* Function rename

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-08-04 22:11:07 +02:00
Christian Clauss
5f4da5d616
isort --profile black . (#2181)
* updating DIRECTORY.md

* isort --profile black .

* Black after

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-07-06 09:44:19 +02:00
Christian Clauss
8ab84fd794
Only one carriage return (#2155)
* updating DIRECTORY.md

* touch

* fixup! Format Python code with psf/black push

* Update word_frequency_functions.py

* updating DIRECTORY.md

* Update word_frequency_functions.py

* Update lfu_cache.py

* Update sol1.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-06-25 19:15:30 +02:00
Tapajyoti Bose
9eb3138b81
Added LFU Cache (#2151)
* Added LFU Cache

* Update lfu_cache.py

* None is returned

* Add type hints

Co-authored-by: Christian Clauss <cclauss@me.com>
2020-06-25 11:40:50 +02:00
Tapajyoti Bose
27dde06dfa
Added LRU Cache (#2138)
* Added LRU Cache

* Optimized the program

* Added Cache as Decorator + Implemented suggestions

* Implemented suggestions
2020-06-25 11:40:03 +02:00
Christian Clauss
5b6ebf8f12
Add doctests to radix_sort() (#2148)
* Add doctests to radix_sort()

* fixup! Format Python code with psf/black push

* Update radix_sort.py

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-06-23 15:37:24 +02:00
Tapajyoti Bose
f1ce2d6e80
Added Markov Chain (#2146)
* Added Markov Chain

* Implemented suggestions
2020-06-23 12:56:08 +02:00
Christian Clauss
9316e7c014
Set the Python file maximum line length to 88 characters (#2122)
* flake8 --max-line-length=88

* fixup! Format Python code with psf/black push

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-06-16 10:09:19 +02:00
mateuszz0000
bb5552efd0
Euclidean recursive method + doctests + type hints (#1999)
* Recursive euclidean algorithm + doctests and type hints

* Fix doctests in recursive method

* Added commit suggestions
2020-05-25 12:32:57 +02:00
Christian Clauss
1f8a21d727
Tighten up psf/black and flake8 (#2024)
* Tighten up psf/black and flake8

* Fix some tests

* Fix some E741

* Fix some E741

* updating DIRECTORY.md

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-22 08:10:11 +02:00
mateuszz0000
2431001658
Easter date gauss algorithm (#2010)
* Added gauss easter algorithm

* Fixes in easter algorithm

* Commit suggestions
2020-05-19 13:44:45 +02:00
Christian Clauss
6acd7fb5ce
Wrap lines that go beyond GitHub Editor (#1925)
* Wrap lines that go beyond GiHub Editor

* flake8 --count --select=E501 --max-line-length=127

* updating DIRECTORY.md

* Update strassen_matrix_multiplication.py

* fixup! Format Python code with psf/black push

* Update decision_tree.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2020-05-01 23:36:35 +02:00