Commit Graph

135 Commits

Author SHA1 Message Date
Hetarth Jain
35dd529c85
Returning Index instead of boolean in knuth_morris_pratt (kmp) function, making it compatible with str.find(). (#9083)
* Update knuth_morris_pratt.py - changed Boolean to Index

* Update knuth_morris_pratt.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update knuth_morris_pratt.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update knuth_morris_pratt.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update back_propagation_neural_network.py

* Update back_propagation_neural_network.py

* Update strings/knuth_morris_pratt.py

* Update knuth_morris_pratt.py

* Update knuth_morris_pratt.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2023-09-28 20:24:46 +02:00
pre-commit-ci[bot]
421ace81ed
[pre-commit.ci] pre-commit autoupdate (#9013)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.285 → v0.0.286](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.285...v0.0.286)
- [github.com/tox-dev/pyproject-fmt: 0.13.1 → 1.1.0](https://github.com/tox-dev/pyproject-fmt/compare/0.13.1...1.1.0)

* updating DIRECTORY.md

* Fis ruff rules PIE808,PLR1714

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2023-08-29 15:18:10 +02:00
Caeden Perelli-Harris
4b7ecb6a81
Create is valid email address algorithm (#8907)
* feat(strings): Create is valid email address

* updating DIRECTORY.md

* feat(strings): Create is_valid_email_address algorithm

* chore(is_valid_email_address): Implement changes from code review

* Update strings/is_valid_email_address.py

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore(is_valid_email_address): Fix ruff error

* Update strings/is_valid_email_address.py

Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-08-14 01:28:52 -07:00
Christian Clauss
dbaff34572
Fix ruff rules ISC flake8-implicit-str-concat (#8892) 2023-07-28 17:53:09 +01:00
Caeden Perelli-Harris
93fb169627
[Upgrade Ruff] Fix all errors raised from ruff (#8879)
* chore: Fix tests

* chore: Fix failing ruff

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* chore: Fix ruff errors

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* chore: Fix ruff errors

* chore: Fix ruff errors

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update cellular_automata/game_of_life.py

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

* chore: Update ruff version in pre-commit

* chore: Fix ruff errors

* Update edmonds_karp_multiple_source_and_sink.py

* Update factorial.py

* Update primelib.py

* Update min_cost_string_conversion.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2023-07-22 12:05:10 +02:00
Christian Clauss
4b79d771cd
Add more ruff rules (#8767)
* Add more ruff rules

* Add more ruff rules

* pre-commit: Update ruff v0.0.269 -> v0.0.270

* Apply suggestions from code review

* Fix doctest

* Fix doctest (ignore whitespace)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-05-26 09:34:17 +02:00
Caeden Perelli-Harris
cfbbfd9896
Merge and add benchmarks to palindrome algorithms in the strings/ directory (#8749)
* refactor: Merge and add benchmarks to palindrome

* updating DIRECTORY.md

* chore: Fix failing tests

* Update strings/palindrome.py

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

* Update palindrome.py

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2023-05-25 12:56:23 +02:00
Margaret
997d56fb63
Switch case (#7995) 2023-05-11 06:53:47 +12:00
Christian Clauss
4c1f876567
Solving the Top k most frequent words problem using a max-heap (#8685)
* Solving the `Top k most frequent words` problem using a max-heap

* Mentioning Python standard library solution in `Top k most frequent words` docstring

* ruff --fix .

* updating DIRECTORY.md

---------

Co-authored-by: Amos Paribocci <aparibocci@gmail.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-04-27 23:02:07 +05:30
Christian Clauss
c96241b5a5
Replace bandit, flake8, isort, and pyupgrade with ruff (#8178)
* Replace bandit, flake8, isort, and pyupgrade with ruff

* Comment on ruff rules

* updating DIRECTORY.md

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2023-03-15 13:58:25 +01:00
Christian Clauss
64543faa98
Make some ruff fixes (#8154)
* Make some ruff fixes

* Undo manual fix

* Undo manual fix

* Updates from ruff=0.0.251
2023-03-01 17:23:33 +01:00
Christian Clauss
c909da9b08
pre-commit: Upgrade psf/black for stable style 2023 (#8110)
* pre-commit: Upgrade psf/black for stable style 2023

Updating https://github.com/psf/black ... updating 22.12.0 -> 23.1.0 for their `2023 stable style`.
* https://github.com/psf/black/blob/main/CHANGES.md#2310

> This is the first [psf/black] release of 2023, and following our stability policy, it comes with a number of improvements to our stable style…

Also, add https://github.com/tox-dev/pyproject-fmt and https://github.com/abravalheri/validate-pyproject to pre-commit.

I only modified `.pre-commit-config.yaml` and all other files were modified by pre-commit.ci and psf/black.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2023-02-01 18:44:54 +05:30
Abhishek Mulik
32a1ff9359
Update is_palindrome.py (#8022) 2023-01-04 13:47:15 +13:00
Mark Mayo
f32d611689
clean of unnecessary checks, imports, calls (#7993) 2022-11-21 00:00:27 +13:00
Caeden Perelli-Harris
daa1c7529a
Raise error not string (#7945)
* ci: Add `B023` to `.flake8` ignores

* refactor: Return `bool`/raise Exception

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* revert: Remove previous branch commit

* Update data_structures/binary_tree/segment_tree_other.py

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

* feat: Apply `__repr__` changes

* chore: Fix failing tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update data_structures/binary_tree/segment_tree_other.py

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

* test: Fix doctests

* random.choice(population_score[:N_SELECTED])[0]

* Update basic_string.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-11-06 15:54:44 +01:00
ok-open-sc
0c5f1c0130
Increased Readability Of Variables (#6400)
* Increased Readability Of Variables

* Update anagrams.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update anagrams.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-30 08:11:17 +01:00
Harsh Verma
a02e7a1331
Added algorithm for Text Justification in Strings (#7354)
* Added algorithm for Text Justification in Strings

* Added algorithm for Text Justification in Strings
2022-10-29 15:54:32 +02:00
Sineth Sankalpa
327c38d6f0
Srilankan phone number validation (#7706)
* Add is_srilankan_phone_number.py

* Update is_srilankan_phone_number.py
2022-10-29 14:40:14 +02:00
Christian Clauss
19bff003aa
Adopt Python >= 3.8 assignment expressions using auto-walrus (#7737)
* Adopt Python >= 3.8 assignment expressions using auto-walrus

* updating DIRECTORY.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-28 15:54:54 +02:00
SwayamSahu
de3271ec80
Refactoring the syntax using list comprehension (#7749)
* Refactoring the syntax using list comprehension

* Update detecting_english_programmatically.py

* Update detecting_english_programmatically.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-27 23:02:15 +02:00
Caeden Perelli-Harris
9bba42eca8
refactor: Indent ... for visual purposes (#7744) 2022-10-27 19:42:30 +02:00
SwayamSahu
71c7c0bd35
Updated a typo in print statement (#7696)
* Updated a typo in print statement

* Apply suggestions from code review

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
2022-10-26 22:20:00 +02:00
M3talM0nk3y
68f6e9ac30
Added function that checks if a string is an isogram (#7608)
* Added function that checks if a string is an isogram.

* Added wiki reference and fixed comments.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Made function name more self-documenting. Raise ValueError if string contains 1 or more digits. Renamed file. Lowercase string inside function.

* Removed check_isogram.py (file renamed).

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fixed test failure.

* Raise ValueError when string has non-alpha characters. Removed import.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-26 16:31:16 +13:00
Carlos Villar
d8ab8a0a0e
Add Spain National ID validator (#7574) (#7575)
* Add Spain National ID validator (#7574)

* is_spain_national_id()

* Update is_spain_national_id.py

* Some systems add a dash

Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-24 13:33:56 +02:00
Christian Clauss
b8b63469ef
My favorite palindrome (#7455)
* My favorite palindrome

* updating DIRECTORY.md

* Update is_palindrome.py

* Update is_palindrome.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update strings/is_palindrome.py

Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>

* Update is_palindrome.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Caeden Perelli-Harris <caedenperelliharris@gmail.com>
2022-10-23 18:12:49 +02:00
SwayamSahu
0dc95c0a6b
Update comments in check_pangram.py script (#7564)
* Update comments in check_pangram.py script

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update and rename check_pangram.py to is_pangram.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-23 18:00:59 +02:00
Sagar Giri
e7b6d2824a
Change to https. (#7277)
* Change to https.

* Revert the py_tf file.
2022-10-16 09:43:29 +02:00
Caeden
a652905b60
Add Flake8 comprehensions to pre-commit (#7235)
* ci(pre-commit): Add ``flake8-comprehensions`` to ``pre-commit`` (#7233)

* refactor: Fix ``flake8-comprehensions`` errors

* fix: Replace `map` with generator (#7233)

* fix: Cast `range` objects to `list`
2022-10-15 19:29:42 +02:00
Caeden
6e69181d1f
refactor: Replace list() and dict() calls with literals (#7198) 2022-10-15 06:37:03 +05:30
Caeden
d5a9f649b8
Add flake8-builtins to pre-commit and fix errors (#7105)
Ignore `A003`

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2022-10-13 19:53:59 +05:30
Carlos Villar
6118b05f0e
Convert snake_case to camelCase or PascalCase (#7028) (#7034)
* Added snake_case to Camel or Pascal case Fixes: #7028

* Added suggested changes

* Add ending empty line from suggestion

Co-authored-by: Caeden <caedenperelliharris@gmail.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update strings/snake_case_to_camel_pascal_case.py

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

Co-authored-by: Caeden <caedenperelliharris@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-13 08:24:53 +02:00
Abinash Satapathy
1aa7bd9616
Added barcode_validator.py (#6771)
* Update README.md

Added Google Cirq references

* Create barcode_validator.py

Barcode/EAN validator

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update barcode_validator.py

Included docstring and updated variables to snake_case

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update barcode_validator.py

Included docset and updated bugs

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update barcode_validator.py

Implemented the changes asked in review.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update barcode_validator.py

Updated with f-string format

* Update barcode_validator.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2022-10-13 00:56:10 +02:00
Caeden
07e991d553
Add pep8-naming to pre-commit hooks and fixes incorrect naming conventions (#7062)
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038)

* refactor: Fix naming conventions (#7038)

* Update arithmetic_analysis/lu_decomposition.py

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

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038)

* chore: Fix naming conventions in doctests (#7038)

* fix: Temporarily disable project euler problem 104 (#7069)

* chore: Fix naming conventions in doctests (#7038)

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-10-13 00:54:20 +02:00
Beksultan
5754bd09ff
fix typo (#6375) 2022-09-21 16:37:38 +01:00
Margaret
cbf3c6140a
add the dna algorithm (#6323)
* adding the dna algorithm

* following bot recommendations

following bot recommendations for the indentation

* following bot recommendations

following bot recommendations regarding indentation [ again ]

* following bot recommendations

following bot recommendations regarding indentation [ again. ]

* following bot recommendations

following bot recommendations.
2022-09-05 02:51:11 +01:00
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
John Law
9135a1f411
Fix doctests and builds in various files (#6233)
* Fix doctest in hamming distance

* add line break

* try to fix quantum_riper_adder

* fix floating point build
2022-07-06 10:00:05 +02:00
Sedat Aybars Nazlica
89fc7bf0b0
Add hamming distance (#6194)
* Add hamming distance

* Fix doctest

* Refactor

* Raise ValueError when string lengths are different
2022-07-06 15:19:13 +08:00
Margaret
04bc8f01dd
Wave (#6061)
* Added censor function

* Added censor code

* Added comments to the code

* modified censor function

* added decrypt function

* added cypher and decypher functions, deleted censor and decrypt functions

* Deleted decrypt.py

* Deleted censor.py

* edited the crypt and decrypt files

* Update cypher_txt.py

* Remove the endline in cypher.py

* Removed the print at the end of decypher.py

* added 4 new algorithms

* added tests to the four files

* added type hints for the function variables

* Deleted decode message

* Deleted code message

* Welford average algorithm

* added average welford algorithm

* is_narcissistic added

* added a descriptive name

* added max_sectors algorithm

* added find_unique

* added wave algorithm

* deleting average_welford [ in the wrong pr ]

* deleting is_narcissistic [ is in the wrong pr ]

* deleting max_sectors [ is in the wrong pr ]

* deleting find_unique [ is in the wrong pr ]

* deleting censor [ is in the wrong pr ]

* deleting decrypt [ is in the wrong pr ]

* fixed wave.py 

fixed indentation and followed the bots reccomendations

* fixed wave.py again

* fixing wave.py for the third time.

* fixing wave.py

* merging strings/wave.py

merging the suggestion

Co-authored-by: John Law <johnlaw.po@gmail.com>

Co-authored-by: John Law <johnlaw.po@gmail.com>
2022-06-24 00:47:29 +08:00
Ikko Ashimine
dceb30aad6
Fix typo in word_occurrence.py (#6154)
word_occurence -> word_occurrence
2022-05-20 12:03:54 +08:00
Rohan R Bharadwaj
e95ecfaf27
Add missing type annotations for strings directory (#5817)
* Type annotations for `strings/autocomplete_using_trie.py`

* Update autocomplete_using_trie.py

* Update detecting_english_programmatically.py

* Update detecting_english_programmatically.py

* Update frequency_finder.py

* Update frequency_finder.py

* Update frequency_finder.py

* Update word_occurrence.py

* Update frequency_finder.py

* Update z_function.py

* Update z_function.py

* Update frequency_finder.py
2022-05-13 13:55:53 +08:00
Shuangchi He
e1ec661d4e
Fix some typos (#6113)
* Fix some typos.

* Update volume.py

Co-authored-by: John Law <johnlaw.po@gmail.com>
2022-05-01 18:44:23 +08:00
Harshit Agarwal
1f1daaf1c7
feat: add strings/ngram algorithm (#6074)
* feat: added ngram algorithm
* fix(test): use `math.isclose` to match floating point numbers approximately

Co-authored-by: Christian Clauss <cclauss@me.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2022-04-04 09:06:32 +05:30
Leoriem-code
4c9949f636
edited strings/anagram.py (#5770)
* rewrote anagrams.py, added doctests

* corrected mistakes

* add anagrams.txt

* Update anagrams.py

* Update strings/anagrams.py

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

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-11-08 18:58:15 +01:00
Rohan R Bharadwaj
99cf2cc1c5
Fix build issues due to count (#5725)
* Fix build issues due to count

* Update check_anagrams.py
2021-10-31 22:56:33 +01:00
Morteza
9ac94c09eb
Improve checking anagrams in O(n) with dictionary (#4806) 2021-10-31 11:41:39 +01:00
@im_8055
a94c6214ff
Fix spellings (#5710) 2021-10-31 11:36:03 +01:00
Navpreet Singh Devpuri
21c99d2ae2
added is_contains_unique_chars() (#5701)
* added is_contains_unique_chars()

* added is_contains_unique_chars()

* added stackoverflow reference
2021-10-30 22:04:46 +02:00
Christian Clauss
366a0f1839
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>
2021-10-26 14:32:34 +02:00
@im_8055
12e81ea6a2
Add credit card string validator (#5583)
* Add credit card validator

* 

* Add return type hint

* Add test cases for validator function

* Add test cases

* Feature: Rename file

* Update strings/cc_validator.py

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

* Update strings/cc_validator.py

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

* Update strings/cc_validator.py

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

* Review: Fix redundant checks

* Review: Refactor

* Fix: Update test cases

* Refactor

* Update credit_card_validator.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-10-26 07:21:07 +02:00