Commit Graph

3401 Commits

Author SHA1 Message Date
Marcus T
5c8a6c8247
Add Pollard's Rho algorithm for integer factorization (#5598) 2021-10-29 01:53:39 +02:00
Dylan Buchi
0590d736fa
[mypy] Fix type annotations in wavelet_tree.py (#5641)
* [mypy] Fix type annotations for wavelet_tree.py

* fix a typo
2021-10-28 22:53:02 +02:00
poloso
61e1dd27b0
[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>
2021-10-28 22:31:32 +02:00
Naveen Namani
11a15cc584
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>
2021-10-28 19:27:14 +02:00
Christian Clauss
477cc3fe59
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>
2021-10-28 16:45:59 +02:00
Víctor A. Rodríguez
70368a757e
Implement Circular Queue using linked lists. Fixes TheAlgorithms#5361 (#5587)
* CircularQueueLinkedList: empty list, trivial implementation TheAlgorithms#5361

* CircularQueueLinkedList: single element list TheAlgorithms#5361

* CircularQueueLinkedList: refactor, no que empty attribute TheAlgorithms#5361

* CircularQueueLinkedList: refactor TheAlgorithms#5361

* CircularQueueLinkedList: changed internal data structure to use double linked list TheAlgorithms#5361

* CircularQueueLinkedList: enqueue test cases added TheAlgorithms#5361

* CircularQueueLinkedList: track full queue TheAlgorithms#5361

* CircularQueueLinkedList: adding functions description TheAlgorithms#5361

* CircularQueueLinkedList: type hints TheAlgorithms#5361

* CircularQueueLinkedList: algorithm explanation TheAlgorithms#5361

* CircularQueueLinkedList: missing type hints TheAlgorithms#5361

* CircularQueueLinkedList: more missing type hints TheAlgorithms#5361

* Update data_structures/queue/circular_queue_linked_list.py

Co-authored-by: John Law <johnlaw.po@gmail.com>
2021-10-28 22:43:24 +08:00
Dylan Buchi
bf6db32ec2
[mypy] Fix type annotations for binary tree traversals in data structures (#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>
2021-10-28 22:05:31 +08:00
@im_8055
6b6762bde9
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.
2021-10-27 19:18:21 +02:00
Rohan R Bharadwaj
615c428903
Add doctest for exception (#5629)
* Add doctest for exception

* Spelling correction
2021-10-27 18:30:03 +02:00
Prakhar Gurunani
329feb4928
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>
2021-10-27 17:19:04 +08:00
harshitkap00r
ce9a139b56
Update binary_search.py (#4856)
Take less time to calculate
2021-10-27 12:25:48 +08:00
Tianyi Zheng
fe5c711ce6
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>
2021-10-27 11:48:43 +08:00
Dylan Buchi
8285913e81
[mypy] Fix and add type annotations (#5618) 2021-10-27 11:45:33 +08:00
Matteo Messmer
4eb5c12727
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>
2021-10-27 00:28:26 +02:00
Edward Nuno
9a03919052
[mypy] Fix type annotations for stack_using_dll.py (#5577)
* Fix mypy annotations for stack_using_dll.py

* Replace Optional with inline union type
2021-10-26 21:12:46 +02:00
Edward Nuno
c0ed031b3f
Fix type annotations for stack.py (#5566) 2021-10-26 20:33:08 +02:00
Sabari Ganesh
582f57f41f
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
2021-10-26 19:55:41 +02:00
Srishtik Bhandarkar
b4036b70f1
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>
2021-10-27 01:10:15 +08:00
Connor Bottum
31061aacf2
fix: use += in sorts/recursive_mergesort_array.py (#5019) 2021-10-27 00:43:46 +08:00
Christian Clauss
cb4dc19723
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>
2021-10-27 00:41:32 +08:00
Tarcisio Bruni Rangel
c41bb49fc0
Financials (#5585)
* 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>
2021-10-26 18:19:00 +02:00
Sabari Ganesh
23f43afee5
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
2021-10-26 17:57:59 +02:00
Rohan R Bharadwaj
6fcefc0453
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
2021-10-26 15:23:38 +02:00
Prakhar Gurunani
827b8f04a4
Get top 10 HN posts (#5604)
* 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>
2021-10-26 15:13:23 +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
Erwin Junge
700398ec06
[mypy] annotate ciphers (#5569)
* [mypy] annotate `ciphers`

* Update ciphers/polybius.py

* Update polybius.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-10-26 12:35:21 +02:00
Erwin Junge
e49d8e3af4
[mypy] annotate compression (#5570) 2021-10-26 12:29:27 +02: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
Prakhar Gurunani
f93c7d4d80
Get user tweets (#5593)
* 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>
2021-10-26 10:05:13 +02:00
Leoriem-code
8e857e8692
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>
2021-10-26 09:57:49 +02:00
Leoriem-code
716beb32ed
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>
2021-10-26 09:21:44 +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
Mohammad Firmansyah
74e442e979
add an algorithm to spin some words (#5597)
* add an algorithm to spin some words

* Update index.py

* Adding type hint of spin_words function

* Update and rename python_codewars_disemvowel/index.py to strings/reverse_long_words.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-10-25 19:18:41 +02:00
Maxim Smolskiy
b55da04602
Improve Project Euler problem 058 solution 1 (#4782)
* Fix typo

* Improve solution

* Retest

* Replace n with number
2021-10-25 16:07:10 +08:00
Maxim Smolskiy
5f7bb3e9f7
Improve Project Euler problem 034 solution 1 (#5165) 2021-10-25 16:03:22 +08:00
Manuel Di Lullo
ba71005484
Add random graph generator (#5240)
* added complete graph generator function

* added doctest, type hints, wikipedia explanation

* added return type hint for function complete_graph

* added descriptive name for the parameter: n

* random graph generator with doctest and type hints

* validated using pre-commit

* Delete complete_graph_generator.py

* fixed doctest

* updated following reviews

* simplified the code following reviews

* fixed doctest and solved consistency issues

* consistency fixes
2021-10-25 15:59:52 +08:00
Francisco Perez
568c107e68
add bin_to_hexadecimal (#5156) 2021-10-25 15:58:24 +08:00
Vinicius Cordeiro
fc5d29e214
Add Bifid cipher (#5493)
* Add Bifid cipher

* Add missing type hint

* Fix variable names
2021-10-24 22:33:53 +02:00
Marcel Kuhmann
5772d0734b
fix dead link (#5572) 2021-10-24 18:44:15 +02:00
Erwin Junge
aaaa175b66
[mypy] annotate computer_vision (#5571) 2021-10-23 23:26:21 +02:00
Martmists
00a67010e8
Simple audio filters (#5230)
* Add IIR Filter and Butterworth design functions

Signed-off-by: Martmists <martmists@gmail.com>

* naming conventions and missing type hints

Signed-off-by: Martmists <martmists@gmail.com>

* Link wikipedia in IIRFilter

Signed-off-by: Martmists <martmists@gmail.com>

* Add doctests and None return types

Signed-off-by: Martmists <martmists@gmail.com>

* More doctests

Signed-off-by: Martmists <martmists@gmail.com>

* Requested changes

Signed-off-by: Martmists <martmists@gmail.com>

* run pre-commit

Signed-off-by: Martmists <martmists@gmail.com>

* Make mypy stop complaining about ints vs floats

Signed-off-by: Martmists <martmists@gmail.com>

* Use slower listcomp to make it more readable

Signed-off-by: Martmists <martmists@gmail.com>

* Make doctests happy

Signed-off-by: Martmists <martmists@gmail.com>

* Remove scipy

Signed-off-by: Martmists <martmists@gmail.com>

* Test coefficients from bw filters

Signed-off-by: Martmists <martmists@gmail.com>

* Protocol test

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

* Make requested change

Signed-off-by: Martmists <martmists@gmail.com>

* Types

Signed-off-by: Martmists <martmists@gmail.com>

* Apply suggestions from code review

* Apply suggestions from code review

* Update butterworth_filter.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-10-23 23:19:25 +02:00
Christian Clauss
bd9464e4ac
mandelbrot.py: Commenting out long running tests (#5558)
* mandelbrot.py: Commenting out long running tests

* updating DIRECTORY.md

* Comment out 9 sec doctests

* Update bidirectional_breadth_first_search.py

* Comment out slow tests

* Comment out slow (9.15 sec) pytests...

* # Comment out slow (4.20s call) doctests

* Comment out slow (3.45s) doctests

* Update miller_rabin.py

* Update miller_rabin.py

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
2021-10-23 18:15:30 +02:00
Studiex
218d8921db
Implementation of SHA-256 using Python (#5532)
* Add files via upload

* Update sha256.py

* Update sha256.py

* Update sha256.py

* Update sha256.py

* Update sha256.py

* Update sha256.py

* Update sha256.py

* Update sha256.py

* @staticmethod def preprocessing(data: bytes) -> bytes:

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-10-23 15:20:52 +02:00
Limbad Yash
80a885c975
Update pop function (#5544)
* Updated Pop function

Added underflow condition

* Update Pop Function

Added condition to check underflow of stack

* Update stack.py

* if not self.stack: raise StackUnderflowError

* Add doctests

* StackUnderflowError

* ..., not ....

* Update stack.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-10-23 15:18:09 +02:00
Mitheel
b72a66b713
Fixed grammatical errors in CONTRIBUTING.md (#5555) 2021-10-23 14:54:41 +02:00
Jaydeep Das
b64fd56776
Added feature to web_programming/nasa_data.py : Can download the APOD image to a specified location on disk. (#5551)
* Added a feature to download images.

* Minor changes

* Update nasa_data.py

* :

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-10-23 14:38:25 +02:00
Jaydeep Das
27f2465135
Added new file: nasa_data.py (#5543)
* Added new file: nasa_data.py

* Modified as per review

* Minor change

* print(get_archive_data("apollo 2011")["collection"]["items"][0]["data"][0]["description"])

* Update nasa_data.py

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-10-23 12:56:26 +02:00
Atishaye Jain
c50f0c56aa
add check_cycle.py (#5475)
* add check_cycle.py

* Update graphs/check_cycle.py

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

* Update check_cycle.py

* Apply suggestions from code review

Co-authored-by: John Law <johnlaw.po@gmail.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2021-10-23 12:29:42 +02:00
Dylan Buchi
20e09c3ec2
[mypy] Add type annotations for linked queue in data structures (#5533)
* [mypy] Add/fix type annotations for linked queue in data_structures

* add return type annotation to __iter__

* Add more readable syntax
2021-10-23 11:56:58 +02:00