Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: imSanko/Python
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: TheAlgorithms/Python
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
Loading
Showing with 6,105 additions and 1,369 deletions.
  1. +1 −1 .devcontainer/Dockerfile
  2. +1 −1 .devcontainer/devcontainer.json
  3. +0 −2 .github/CODEOWNERS
  4. +9 −10 .github/workflows/build.yml
  5. +6 −10 .github/workflows/project_euler.yml
  6. +2 −2 .github/workflows/ruff.yml
  7. +50 −0 .github/workflows/sphinx.yml
  8. +6 −6 .pre-commit-config.yaml
  9. +2 −2 CONTRIBUTING.md
  10. +57 −20 DIRECTORY.md
  11. +1 −1 LICENSE.md
  12. +19 −13 audio_filters/iir_filter.py
  13. +34 −0 backtracking/all_combinations.py
  14. +13 −6 backtracking/n_queens.py
  15. +37 −0 bit_manipulation/find_unique_number.py
  16. +16 −4 boolean_algebra/and_gate.py
  17. +2 −4 cellular_automata/conways_game_of_life.py
  18. +26 −28 cellular_automata/wa_tor.py
  19. +21 −2 ciphers/autokey.py
  20. +6 −6 ciphers/{base64.py → base64_cipher.py}
  21. +48 −31 ciphers/caesar_cipher.py
  22. +51 −48 ciphers/decrypt_caesar_with_chi_squared.py
  23. +35 −29 ciphers/enigma_machine2.py
  24. +45 −0 ciphers/gronsfeld_cipher.py
  25. +1 −1 ciphers/playfair_cipher.py
  26. +8 −5 ciphers/rsa_factorization.py
  27. +10 −2 ciphers/simple_keyword_cypher.py
  28. +2 −4 ciphers/transposition_cipher.py
  29. +17 −12 ciphers/trifid_cipher.py
  30. +0 −1 computer_vision/README.md
  31. +1 −1 computer_vision/flip_augmentation.py
  32. +62 −0 computer_vision/intensity_based_segmentation.py
  33. +1 −1 computer_vision/mosaic_augmentation.py
  34. +4 −4 conversions/convert_number_to_words.py
  35. +2 −2 conversions/prefix_conversions_string.py
  36. +32 −0 conversions/rectangular_to_polar.py
  37. 0 {compression → data_compression}/README.md
  38. 0 {compression → data_compression}/__init__.py
  39. 0 {compression → data_compression}/burrows_wheeler.py
  40. 0 {compression → data_compression}/huffman.py
  41. BIN {compression → data_compression}/image_data/PSNR-example-base.png
  42. BIN {compression → data_compression}/image_data/PSNR-example-comp-10.jpg
  43. BIN {compression → data_compression}/image_data/compressed_image.png
  44. BIN {compression → data_compression}/image_data/example_image.jpg
  45. BIN {compression → data_compression}/image_data/example_wikipedia_image.jpg
  46. BIN {compression → data_compression}/image_data/original_image.png
  47. +2 −2 {compression → data_compression}/lempel_ziv.py
  48. 0 {compression → data_compression}/lempel_ziv_decompress.py
  49. 0 {compression → data_compression}/lz77.py
  50. 0 {compression → data_compression}/peak_signal_to_noise_ratio.py
  51. 0 {compression → data_compression}/run_length_encoding.py
  52. +14 −0 data_structures/arrays/monotonic_array.py
  53. +19 −1 data_structures/arrays/prefix_sum.py
  54. +49 −23 data_structures/arrays/sudoku_solver.py
  55. +4 −0 data_structures/binary_tree/avl_tree.py
  56. +10 −14 data_structures/binary_tree/binary_tree_traversals.py
  57. +54 −0 data_structures/binary_tree/lowest_common_ancestor.py
  58. +78 −0 data_structures/binary_tree/maximum_sum_bst.py
  59. +29 −23 data_structures/binary_tree/mirror_binary_tree.py
  60. +3 −3 data_structures/hashing/number_theory/prime_numbers.py
  61. +3 −3 data_structures/heap/min_heap.py
  62. +6 −6 data_structures/kd_tree/tests/test_kdtree.py
  63. +1 −1 data_structures/linked_list/deque_doubly.py
  64. +53 −40 data_structures/linked_list/doubly_linked_list_two.py
  65. +1 −1 data_structures/linked_list/from_sequence.py
  66. 0 {compression/image_data → data_structures/queues}/__init__.py
  67. +7 −3 data_structures/{queue → queues}/circular_queue.py
  68. 0 data_structures/{queue → queues}/circular_queue_linked_list.py
  69. +1 −1 data_structures/{queue → queues}/double_ended_queue.py
  70. 0 data_structures/{queue → queues}/linked_queue.py
  71. +3 −3 data_structures/{queue → queues}/priority_queue_using_list.py
  72. 0 data_structures/{queue → queues}/queue_by_list.py
  73. 0 data_structures/{queue → queues}/queue_by_two_stacks.py
  74. 0 data_structures/{queue → queues}/queue_on_pseudo_stack.py
  75. +39 −0 data_structures/stacks/largest_rectangle_histogram.py
  76. +38 −0 data_structures/stacks/lexicographical_numbers.py
  77. +36 −3 data_structures/stacks/prefix_evaluation.py
  78. +12 −12 data_structures/suffix_tree/tests/test_suffix_tree.py
  79. +7 −5 divide_and_conquer/power.py
  80. 0 {data_structures/queue → docs}/__init__.py
  81. +3 −0 docs/conf.py
  82. +4 −3 dynamic_programming/all_construct.py
  83. +3 −3 dynamic_programming/bitmask.py
  84. +3 −3 dynamic_programming/climbing_stairs.py
  85. +12 −11 dynamic_programming/combination_sum_iv.py
  86. +6 −5 dynamic_programming/fizz_buzz.py
  87. +3 −3 dynamic_programming/iterating_through_submasks.py
  88. +21 −19 dynamic_programming/knapsack.py
  89. +18 −0 dynamic_programming/longest_common_subsequence.py
  90. +18 −11 dynamic_programming/longest_common_substring.py
  91. +12 −7 dynamic_programming/longest_increasing_subsequence.py
  92. +72 −0 dynamic_programming/longest_increasing_subsequence_iterative.py
  93. +49 −42 dynamic_programming/matrix_chain_multiplication.py
  94. +2 −1 dynamic_programming/max_product_subarray.py
  95. +1 −0 dynamic_programming/minimum_squares_to_represent_a_number.py
  96. +92 −0 dynamic_programming/range_sum_query.py
  97. +12 −10 dynamic_programming/regex_match.py
  98. +46 −37 dynamic_programming/rod_cutting.py
  99. +33 −30 dynamic_programming/subset_generation.py
  100. +93 −119 dynamic_programming/viterbi.py
  101. +20 −0 electronics/electric_conductivity.py
  102. +6 −4 electronics/electric_power.py
  103. +1 −1 electronics/electrical_impedance.py
  104. +1 −1 financial/{ABOUT.md → README.md}
  105. +40 −0 financial/time_and_half_pay.py
  106. +3 −3 genetic_algorithm/basic_string.py
  107. +3 −2 geodesy/haversine_distance.py
  108. +29 −0 geometry/geometry.py
  109. +46 −0 graphics/butterfly_pattern.py
  110. +52 −0 graphics/digital_differential_analyzer_line.py
  111. +2 −4 graphs/ant_colony_optimization_algorithms.py
  112. +43 −11 graphs/basic_graphs.py
  113. +14 −10 graphs/check_bipatrite.py
  114. +206 −0 graphs/lanczos_eigenvectors.py
  115. +4 −4 graphs/minimum_spanning_tree_boruvka.py
  116. +2 −2 graphs/minimum_spanning_tree_prims2.py
  117. +2 −1 greedy_methods/smallest_range.py
  118. +2 −2 hashes/enigma_machine.py
  119. +1 −1 hashes/md5.py
  120. +10 −0 index.md
  121. +19 −9 linear_algebra/gaussian_elimination.py
  122. +11 −9 linear_algebra/lu_decomposition.py
  123. +36 −0 linear_algebra/matrix_inversion.py
  124. +20 −26 linear_algebra/src/gaussian_elimination_pivoting.py
  125. +10 −1 linear_algebra/src/lib.py
  126. +24 −18 linear_algebra/src/polynom_for_points.py
  127. +5 −1 linear_algebra/src/rank_of_matrix.py
  128. +7 −6 linear_algebra/src/schur_complement.py
  129. +1 −1 linear_algebra/src/test_linear_algebra.py
  130. +8 −6 linear_algebra/src/transformations_2d.py
  131. +2 −2 machine_learning/frequent_pattern_growth.py
  132. +2 −2 machine_learning/linear_discriminant_analysis.py
  133. +32 −2 machine_learning/linear_regression.py
  134. 0 machine_learning/local_weighted_learning/{local_weighted_learning.md → README.md}
  135. +85 −0 machine_learning/principle_component_analysis.py
  136. +1 −1 maths/collatz_sequence.py
  137. +16 −2 maths/decimal_to_fraction.py
  138. +2 −4 maths/dual_number_automatic_differentiation.py
  139. +55 −0 maths/geometric_mean.py
  140. +28 −9 maths/is_ip_v4_address_valid.py
  141. +32 −4 maths/matrix_exponentiation.py
  142. +3 −1 maths/max_sum_sliding_window.py
  143. +6 −6 maths/numerical_analysis/integration_by_simpson_approx.py
  144. +5 −0 maths/numerical_analysis/intersection.py
  145. +14 −5 maths/perfect_number.py
  146. +8 −0 maths/power_using_recursion.py
  147. +6 −6 maths/prime_check.py
  148. +3 −3 maths/prime_numbers.py
  149. +22 −22 maths/primelib.py
  150. +4 −4 maths/special_numbers/armstrong_numbers.py
  151. +4 −0 maths/special_numbers/bell_numbers.py
  152. +5 −1 maths/special_numbers/hamming_numbers.py
  153. +8 −0 maths/special_numbers/harshad_numbers.py
  154. +74 −19 maths/trapezoidal_rule.py
  155. +96 −55 maths/volume.py
  156. +11 −4 maths/zellers_congruence.py
  157. +284 −0 matrix/matrix_based_game.py
  158. +7 −9 neural_network/input_data.py
  159. +10 −6 other/bankers_algorithm.py
  160. +52 −44 other/davis_putnam_logemann_loveland.py
  161. +1 −1 other/doomsday.py
  162. +10 −8 other/lfu_cache.py
  163. +10 −8 other/lru_cache.py
  164. +1 −1 other/quine.py
  165. +16 −14 other/scoring_algorithm.py
  166. +4 −5 physics/basic_orbital_capture.py
  167. +67 −0 physics/escape_velocity.py
  168. +1 −1 physics/grahams_law.py
  169. +50 −36 physics/horizontal_projectile_motion.py
  170. +47 −36 physics/newtons_second_law_of_motion.py
  171. +73 −0 physics/orbital_transfer_work.py
  172. +53 −0 physics/period_of_pendulum.py
  173. +23 −21 physics/speeds_of_gas_molecules.py
  174. +1 −1 project_euler/problem_002/sol4.py
  175. +1 −1 project_euler/problem_025/sol2.py
  176. +1 −1 project_euler/problem_028/sol1.py
  177. +6 −6 project_euler/problem_047/sol1.py
  178. 0 {source → project_euler/problem_095}/__init__.py
  179. +164 −0 project_euler/problem_095/sol1.py
  180. 0 project_euler/problem_122/__init__.py
  181. +89 −0 project_euler/problem_122/sol1.py
  182. +1 −1 project_euler/problem_123/sol1.py
  183. 0 project_euler/problem_136/__init__.py
  184. +63 −0 project_euler/problem_136/sol1.py
  185. 0 project_euler/problem_164/__init__.py
  186. +65 −0 project_euler/problem_164/sol1.py
  187. 0 project_euler/problem_190/__init__.py
  188. +48 −0 project_euler/problem_190/sol1.py
  189. 0 project_euler/problem_345/__init__.py
  190. +117 −0 project_euler/problem_345/sol1.py
  191. +139 −8 pyproject.toml
  192. +3 −8 requirements.txt
  193. +16 −0 scripts/find_git_conflicts.sh
  194. +8 −10 scripts/validate_filenames.py
  195. +14 −5 scripts/validate_solutions.py
  196. +113 −0 searches/exponential_search.py
  197. +2 −0 sorts/bubble_sort.py
  198. +1 −1 sorts/external_sort.py
  199. +28 −19 sorts/heap_sort.py
  200. +23 −0 sorts/quick_sort_3_partition.py
  201. +2 −2 strings/frequency_finder.py
  202. +3 −1 strings/jaro_winkler.py
  203. +24 −4 strings/join.py
  204. +12 −4 strings/min_cost_string_conversion.py
  205. +4 −1 strings/split.py
  206. 0 strings/{wave.py → wave_string.py}
  207. +1,302 −0 uv.lock
  208. +10 −3 web_programming/co2_emission.py
  209. +10 −2 web_programming/covid_stats_via_xpath.py
  210. +16 −2 web_programming/crawl_google_results.py
  211. +10 −2 web_programming/crawl_google_scholar_citation.py
  212. +9 −2 web_programming/currency_converter.py
  213. +34 −8 web_programming/current_stock_price.py
  214. +10 −3 web_programming/current_weather.py
  215. +10 −2 web_programming/daily_horoscope.py
  216. +10 −2 web_programming/download_images_from_google_query.py
  217. +17 −4 web_programming/emails_from_url.py
  218. +17 −8 web_programming/fetch_anime_and_play.py
  219. +9 −2 web_programming/fetch_bbc_news.py
  220. +10 −3 web_programming/fetch_github_info.py
  221. +11 −5 web_programming/fetch_jobs.py
  222. +10 −3 web_programming/fetch_quotes.py
  223. +11 −2 web_programming/get_amazon_product_data.py
  224. +12 −4 web_programming/get_imdb_top_250_movies_csv.py
  225. +10 −3 web_programming/get_ip_geolocation.py
  226. +10 −2 web_programming/get_top_billionaires.py
  227. +10 −3 web_programming/get_top_hn_posts.py
  228. +10 −2 web_programming/giphy.py
  229. +12 −2 web_programming/instagram_crawler.py
  230. +14 −6 web_programming/instagram_pic.py
  231. +11 −4 web_programming/instagram_video.py
  232. +11 −6 web_programming/nasa_data.py
  233. +13 −12 web_programming/open_google_results.py
  234. +12 −3 web_programming/random_anime_character.py
  235. +9 −2 web_programming/recaptcha_verification.py
  236. +12 −4 web_programming/reddit.py
  237. +14 −7 web_programming/search_books_by_isbn.py
  238. +9 −2 web_programming/slack_message.py
  239. +2 −2 web_programming/test_fetch_github_info.py
  240. +19 −7 web_programming/world_covid19_stats.py
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# https://github.com/microsoft/vscode-dev-containers/blob/main/containers/python-3/README.md
ARG VARIANT=3.12-bookworm
ARG VARIANT=3.13-bookworm
FROM mcr.microsoft.com/vscode/devcontainers/python:${VARIANT}
COPY requirements.txt /tmp/pip-tmp/
RUN python3 -m pip install --upgrade pip \
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
// Update 'VARIANT' to pick a Python version: 3, 3.11, 3.10, 3.9, 3.8
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"VARIANT": "3.12-bookworm",
"VARIANT": "3.13-bookworm",
}
},

2 changes: 0 additions & 2 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -9,8 +9,6 @@

/.* @cclauss

# /arithmetic_analysis/

# /backtracking/

# /bit_manipulation/
19 changes: 9 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -10,28 +10,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: uv.lock
- uses: actions/setup-python@v5
with:
python-version: 3.13
allow-prereleases: true
- uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install pytest-cov -r requirements.txt
- run: uv sync --group=test
- name: Run tests
# TODO: #8818 Re-enable quantum tests
run: pytest
--ignore=quantum/q_fourier_transform.py
run: uv run pytest
--ignore=computer_vision/cnn_classification.py
--ignore=docs/conf.py
--ignore=dynamic_programming/k_means_clustering_tensorflow.py
--ignore=machine_learning/lstm/lstm_prediction.py
--ignore=neural_network/input_data.py
--ignore=project_euler/
--ignore=quantum/q_fourier_transform.py
--ignore=scripts/validate_solutions.py
--ignore=web_programming/fetch_anime_and_play.py
--cov-report=term-missing:skip-covered
--cov=. .
- if: ${{ success() }}
16 changes: 6 additions & 10 deletions .github/workflows/project_euler.yml
Original file line number Diff line number Diff line change
@@ -15,25 +15,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install pytest and pytest-cov
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade numpy pytest pytest-cov
- run: pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/
- run: uv sync --group=euler-validate --group=test
- run: uv run pytest --doctest-modules --cov-report=term-missing:skip-covered --cov=project_euler/ project_euler/
validate-solutions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Install pytest and requests
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade numpy pytest requests
- run: pytest scripts/validate_solutions.py
- run: uv sync --group=euler-validate --group=test
- run: uv run pytest scripts/validate_solutions.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -12,5 +12,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pip install --user ruff
- run: ruff check --output-format=github .
- uses: astral-sh/setup-uv@v6
- run: uvx ruff check --output-format=github .
50 changes: 50 additions & 0 deletions .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: sphinx

on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: ["master"]
pull_request:
branches: ["master"]
# Or manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build_docs:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v6
- uses: actions/setup-python@v5
with:
python-version: 3.13
allow-prereleases: true
- run: uv sync --group=docs
- uses: actions/configure-pages@v5
- run: uv run sphinx-build -c docs . docs/_build/html
- uses: actions/upload-pages-artifact@v3
with:
path: docs/_build/html

deploy_docs:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
if: github.event_name != 'pull_request'
needs: build_docs
runs-on: ubuntu-latest
steps:
- uses: actions/deploy-pages@v4
id: deployment
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-executables-have-shebangs
- id: check-toml
@@ -16,20 +16,20 @@ repos:
- id: auto-walrus

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.8
rev: v0.11.9
hooks:
- id: ruff
- id: ruff-format

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
additional_dependencies:
- tomli

- repo: https://github.com/tox-dev/pyproject-fmt
rev: "2.2.4"
rev: "v2.5.1"
hooks:
- id: pyproject-fmt

@@ -42,12 +42,12 @@ repos:
pass_filenames: false

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.20.2
rev: v0.24.1
hooks:
- id: validate-pyproject

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
rev: v1.15.0
hooks:
- id: mypy
args:
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ pre-commit run --all-files --show-diff-on-failure

We want your work to be readable by others; therefore, we encourage you to note the following:

- Please write in Python 3.12+. For instance: `print()` is a function in Python 3 so `print "Hello"` will *not* work but `print("Hello")` will.
- Please write in Python 3.13+. For instance: `print()` is a function in Python 3 so `print "Hello"` will *not* work but `print("Hello")` will.
- Please focus hard on the naming of functions, classes, and variables. Help your reader by using __descriptive names__ that can help you to remove redundant comments.
- Single letter variable names are *old school* so please avoid them unless their life only spans a few lines.
- Expand acronyms because `gcd()` is hard to understand but `greatest_common_divisor()` is not.
@@ -96,7 +96,7 @@ We want your work to be readable by others; therefore, we encourage you to note

```bash
python3 -m pip install ruff # only required the first time
ruff .
ruff check
```

- Original code submission require docstrings or comments to describe your work.
Loading