Skip to content

Commit 49d97e5

Browse files
authored
Merge branch 'master' into patch-1
2 parents f8f7773 + 84b73d0 commit 49d97e5

113 files changed

Lines changed: 3132 additions & 4444 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.devcontainer/devcontainer.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
//
1010
// This repo tracks the latest-and-greatest CPython on the newest stable
1111
// Debian. Images are published per CPython minor version on Debian 13
12-
// "Trixie" (3.11-trixie ... 3.14-trixie); bump this to the newest available
12+
// "Trixie" (3.11-trixie ... 3.15-trixie); bump this to the newest available
1313
// when a new stable CPython ships.
14-
// NOTE: these images do not publish free-threaded (`t`) variants, so 3.14t
14+
// NOTE: these images do not publish free-threaded (`t`) variants, so 3.15t
1515
// cannot be selected via the tag alone -- but the repo's `.python-version`
16-
// pins 3.14t, and `uv run`/`uv sync` in the container honor it, so uv gives
17-
// contributors free-threaded 3.14t regardless of the base tag.
16+
// pins 3.15t, and `uv run`/`uv sync` in the container honor it, so uv gives
17+
// contributors free-threaded 3.15t regardless of the base tag.
1818
"image": "mcr.microsoft.com/devcontainers/python:latest",
1919

2020
// Install the tools post_install and CI expect (pre-commit + ruff), plus uv

‎.github/workflows/build.yml‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,26 @@ jobs:
2020
with:
2121
python-version-file: .python-version
2222
allow-prereleases: true
23-
# keras needs hdf5 on pre-release Python.
24-
- run: |
25-
if [ "$(python -c 'import sys; print(sys.version_info.releaselevel)')" != "final" ]; then
26-
sudo apt-get update -qq
27-
sudo apt-get install --yes libhdf5-dev
28-
fi
2923
- run: uv sync --group=test
3024
- name: Run tests
31-
# opencv-python is gated out on 3.14t (no cp314t wheel yet), so skip the
25+
# opencv-python is gated out on 3.15t (no cp315t wheel yet), so skip the
3226
# files that import cv2. Pure-Python algorithms in computer_vision/ and
3327
# data_compression/ still run; digital_image_processing/ is almost entirely
34-
# cv2-based so it is skipped as a tree. Re-enable when a cp314t wheel ships.
28+
# cv2-based so it is skipped as a tree. Re-enable when a cp315t wheel ships.
3529
# --ignore-gil-enabled: some compiled deps (sklearn, xgboost, ...) don't
3630
# yet ship the Py_mod_gil slot, so importing them re-enables the GIL under
37-
# 3.14t. That's an upstream-wheel gap, not our code; the flag lets the suite
31+
# 3.15t. That's an upstream-wheel gap, not our code; the flag lets the suite
3832
# run anyway and pytest-run-parallel still reports which tests are not
3933
# thread-safe. Drop the flag once the scientific stack ships free-threaded wheels.
40-
# qiskit is likewise gated out of the 3.14t deps (Qiskit/qiskit#16893), so the
41-
# single file that imports it (quantum/q_fourier_transform.py) is skipped too.
4234
run: uv run --with=pytest-run-parallel pytest
4335
--iterations=8 --parallel-threads=auto --ignore-gil-enabled
44-
--ignore=computer_vision/cnn_classification.py
4536
--ignore=computer_vision/flip_augmentation.py
4637
--ignore=computer_vision/harris_corner.py
4738
--ignore=computer_vision/mosaic_augmentation.py
4839
--ignore=data_compression/peak_signal_to_noise_ratio.py
4940
--ignore=digital_image_processing/
5041
--ignore=docs/conf.py
51-
--ignore=dynamic_programming/k_means_clustering_tensorflow.py
52-
--ignore=machine_learning/lstm/lstm_prediction.py
53-
--ignore=neural_network/input_data.py
5442
--ignore=project_euler/
55-
--ignore=quantum/q_fourier_transform.py
5643
--ignore=scripts/validate_solutions.py
5744
--ignore=web_programming/current_stock_price.py
5845
--ignore=web_programming/fetch_anime_and_play.py

‎.github/workflows/hacktoberfest_prep.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ on:
1414
paths:
1515
- ".github/workflows/hacktoberfest_prep.yml"
1616
- "scripts/hacktoberfest_prep_update.py"
17-
schedule:
18-
- cron: "50 11 * * *" # 11:50 UTC every day
17+
# schedule:
18+
# - cron: "50 11 * * *" # 11:50 UTC every day
1919
workflow_dispatch: # allow a manual run while testing
2020

2121
permissions:

‎.github/workflows/sphinx.yml‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ jobs:
3333
with:
3434
python-version-file: .python-version
3535
allow-prereleases: true
36-
# keras needs hdf5 on pre-release Python.
37-
- run: |
38-
if [ "$(python -c 'import sys; print(sys.version_info.releaselevel)')" != "final" ]; then
39-
sudo apt-get update -qq
40-
sudo apt-get install --yes libhdf5-dev
41-
fi
4236
- run: uv sync --group=docs
4337
- uses: actions/configure-pages@v6
4438
- run: uv run sphinx-build -c docs . docs/_build/html

‎.github/workflows/ty.yml‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ jobs:
2828
# [build-system], so uv treats the project as virtual and installs only
2929
# its dependencies -- no "Multiple top-level packages discovered in a
3030
# flat-layout" error and no need for a src-layout. (`uv pip install .`
31-
# would force that wheel build and fail.) Pin a regular GIL 3.14 so typed
32-
# third-party dependencies resolve; the free-threaded 3.14t interpreter the
31+
# would force that wheel build and fail.) Pin a regular GIL 3.15 so typed
32+
# third-party dependencies resolve; the free-threaded 3.15t interpreter the
3333
# test matrix uses lacks wheels for several of them. ty itself is pulled in
3434
# ephemerally with `--with` so it needn't be added to the lockfile.
35-
- run: uv sync --python 3.14
36-
# Pin the *run* to the same regular-GIL 3.14 too. Without `--python 3.14`
35+
- run: uv sync --python 3.15
36+
# Pin the *run* to the same regular-GIL 3.15 too. Without `--python 3.15`
3737
# here, `uv run` re-resolved the project's default interpreter -- the
38-
# free-threaded 3.14t used by the test matrix -- so ty type-checked against
38+
# free-threaded 3.15t used by the test matrix -- so ty type-checked against
3939
# an env where many third-party stubs don't resolve, drowning real findings
40-
# in `unresolved-import` / `unresolved-attribute` noise. Pinning 3.14 lets
40+
# in `unresolved-import` / `unresolved-attribute` noise. Pinning 3.15 lets
4141
# ty see the synced dependencies, so the `[tool.ty.rules]` severities in
4242
# pyproject.toml apply to a meaningful baseline.
4343
#
@@ -50,4 +50,4 @@ jobs:
5050
# to make ty a required gate once the [tool.ty] baseline is clean.
5151
# `continue-on-error: true` above stays as a belt-and-suspenders guard so a
5252
# ty *crash* (not a diagnostic) can never block a merge either.
53-
- run: uv run --python 3.14 --with ty ty check --output-format=github --exit-zero
53+
- run: uv run --python 3.15 --with ty ty check --output-format=github --exit-zero

‎.pre-commit-config.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,9 @@ repos:
6363
rev: "0.26"
6464
hooks:
6565
- id: validate-pyproject
66+
67+
- repo: https://github.com/15r10nk/matchify
68+
rev: v0.2.0
69+
hooks:
70+
- id: matchify
71+
exclude: ^data_structures/linked_list/doubly_linked_list\.py$

‎.python-version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.14t
1+
3.15t

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pre-commit run --all-files --show-diff-on-failure
100100

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

103-
- Please write in free-threaded Python 3.14t+. For instance: `print()` is a function in Python 3, so `print "Hello"` will *not* work, but `print("Hello")` will.
103+
- Please write in free-threaded Python 3.15t+. For instance: `print()` is a function in Python 3, so `print "Hello"` will *not* work, but `print("Hello")` will.
104104

105105
- 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.
106106
- Single-letter variable names are *old school*, so please avoid them unless their life only spans a few lines.

‎DIRECTORY.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
* [Rotate Bits](bit_manipulation/rotate_bits.py)
107107
* [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py)
108108
* [Swap All Odd And Even Bits](bit_manipulation/swap_all_odd_and_even_bits.py)
109+
* [Xor Swap Two Integers](bit_manipulation/xor_swap_two_integers.py)
109110

110111
## [Blockchain](blockchain)
111112
* [Diophantine Equation](blockchain/diophantine_equation.py)
@@ -194,7 +195,6 @@
194195
* [Xtea](ciphers/xtea.py)
195196

196197
## [Computer Vision](computer_vision)
197-
* [Cnn Classification](computer_vision/cnn_classification.py)
198198
* [Flip Augmentation](computer_vision/flip_augmentation.py)
199199
* [Gramian](computer_vision/gramian.py)
200200
* [Haralick Descriptors](computer_vision/haralick_descriptors.py)
@@ -269,13 +269,17 @@
269269
* [Index 2D Array In 1D](data_structures/arrays/index_2d_array_in_1d.py)
270270
* [Kth Largest Element](data_structures/arrays/kth_largest_element.py)
271271
* [Median Two Array](data_structures/arrays/median_two_array.py)
272+
* [Merge Intervals](data_structures/arrays/merge_intervals.py)
273+
* [Merge Sorted](data_structures/arrays/merge_sorted.py)
272274
* [Monotonic Array](data_structures/arrays/monotonic_array.py)
273275
* [Pairs With Given Sum](data_structures/arrays/pairs_with_given_sum.py)
274276
* [Pairwise Iteration](data_structures/arrays/pairwise_iteration.py)
275277
* [Permutations](data_structures/arrays/permutations.py)
276278
* [Prefix Sum](data_structures/arrays/prefix_sum.py)
277279
* [Product Sum](data_structures/arrays/product_sum.py)
280+
* [Reverse Array](data_structures/arrays/reverse_array.py)
278281
* [Rotate Array](data_structures/arrays/rotate_array.py)
282+
* [Set Matrix Zeroes](data_structures/arrays/set_matrix_zeroes.py)
279283
* [Sparse Table](data_structures/arrays/sparse_table.py)
280284
* [Sudoku Solver](data_structures/arrays/sudoku_solver.py)
281285
* Binary Tree
@@ -473,7 +477,6 @@
473477
* [Floyd Warshall](dynamic_programming/floyd_warshall.py)
474478
* [Integer Partition](dynamic_programming/integer_partition.py)
475479
* [Iterating Through Submasks](dynamic_programming/iterating_through_submasks.py)
476-
* [K Means Clustering Tensorflow](dynamic_programming/k_means_clustering_tensorflow.py)
477480
* [Knapsack](dynamic_programming/knapsack.py)
478481
* [Largest Divisible Subset](dynamic_programming/largest_divisible_subset.py)
479482
* [Longest Common Subsequence](dynamic_programming/longest_common_subsequence.py)
@@ -482,6 +485,7 @@
482485
* [Longest Increasing Subsequence Iterative](dynamic_programming/longest_increasing_subsequence_iterative.py)
483486
* [Longest Increasing Subsequence O Nlogn](dynamic_programming/longest_increasing_subsequence_o_nlogn.py)
484487
* [Longest Palindromic Subsequence](dynamic_programming/longest_palindromic_subsequence.py)
488+
* [Longest Repeating Subsequence](dynamic_programming/longest_repeating_subsequence.py)
485489
* [Matrix Chain Multiplication](dynamic_programming/matrix_chain_multiplication.py)
486490
* [Matrix Chain Order](dynamic_programming/matrix_chain_order.py)
487491
* [Max Non Adjacent Sum](dynamic_programming/max_non_adjacent_sum.py)
@@ -557,6 +561,7 @@
557561
* [Sharpe Ratio](financial/sharpe_ratio.py)
558562
* [Simple Moving Average](financial/simple_moving_average.py)
559563
* [Straight Line Depreciation](financial/straight_line_depreciation.py)
564+
* [Streaming Moving Average](financial/streaming_moving_average.py)
560565
* [Time And Half Pay](financial/time_and_half_pay.py)
561566
* [Value At Risk](financial/value_at_risk.py)
562567

@@ -703,6 +708,7 @@
703708
* [Enigma Machine](hashes/enigma_machine.py)
704709
* [Fletcher16](hashes/fletcher16.py)
705710
* [Hamming Code](hashes/hamming_code.py)
711+
* [Jenkins One At A Time](hashes/jenkins_one_at_a_time.py)
706712
* [Luhn](hashes/luhn.py)
707713
* [Md5](hashes/md5.py)
708714
* [Sdbm](hashes/sdbm.py)
@@ -765,8 +771,6 @@
765771
* [Local Weighted Learning](machine_learning/local_weighted_learning/local_weighted_learning.py)
766772
* [Logistic Regression](machine_learning/logistic_regression.py)
767773
* [Loss Functions](machine_learning/loss_functions.py)
768-
* Lstm
769-
* [Lstm Prediction](machine_learning/lstm/lstm_prediction.py)
770774
* [Mab](machine_learning/mab.py)
771775
* [Mean Shift](machine_learning/mean_shift.py)
772776
* [Mfcc](machine_learning/mfcc.py)
@@ -1029,9 +1033,11 @@
10291033
* [Rotate Matrix](matrix/rotate_matrix.py)
10301034
* [Searching In Sorted Matrix](matrix/searching_in_sorted_matrix.py)
10311035
* [Sherman Morrison](matrix/sherman_morrison.py)
1036+
* [Similar Matrices](matrix/similar_matrices.py)
10321037
* [Spiral Print](matrix/spiral_print.py)
10331038
* Tests
10341039
* [Test Matrix Operation](matrix/tests/test_matrix_operation.py)
1040+
* [Transitive Closure](matrix/transitive_closure.py)
10351041
* [Validate Sudoku Board](matrix/validate_sudoku_board.py)
10361042

10371043
## [Networking Flow](networking_flow)
@@ -1056,7 +1062,7 @@
10561062
* [Swish](neural_network/activation_functions/swish.py)
10571063
* [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py)
10581064
* [Convolution Neural Network](neural_network/convolution_neural_network.py)
1059-
* [Input Data](neural_network/input_data.py)
1065+
* [Lstm](neural_network/lstm.py)
10601066
* Optimizers
10611067
* [Adagrad](neural_network/optimizers/adagrad.py)
10621068
* [Adam Optimizer](neural_network/optimizers/adam_optimizer.py)
@@ -1474,7 +1480,6 @@
14741480
* [Sol1](project_euler/problem_800/sol1.py)
14751481

14761482
## [Quantum](quantum)
1477-
* [Q Fourier Transform](quantum/q_fourier_transform.py)
14781483
* [Shor Algorithm](quantum/shor_algorithm.py)
14791484

14801485
## [Scheduling](scheduling)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Information on XOR swap: https://en.wikipedia.org/wiki/Bitwise_operation#XOR
2+
3+
# Algorithm:
4+
# 1. Take two integers a and b.
5+
# 2. Apply XOR between a and b and store the result in a:
6+
# a = a ^ b
7+
# 3. XOR the new value of a with b to get the original value of a and store it in b:
8+
# b = a ^ b
9+
# 4. XOR the new value of a with the new value of b.
10+
# This gives the original value of b, which we store in a:
11+
# a = a ^ b
12+
# 5. Return the swapped values (a, b).
13+
# This method swaps two numbers without using a temporary variable.
14+
15+
16+
def xor_swap(a: int, b: int) -> tuple[int, int]:
17+
"""
18+
Swap two integers using bitwise XOR operation and return the swapped values.
19+
20+
>>> xor_swap(5, 10)
21+
(10, 5)
22+
>>> xor_swap(0, 0)
23+
(0, 0)
24+
>>> xor_swap(-1, 1)
25+
(1, -1)
26+
>>> xor_swap(123, 456)
27+
(456, 123)
28+
>>> xor_swap(12345, 54321)
29+
(54321, 12345)
30+
"""
31+
a = a ^ b
32+
b = a ^ b
33+
a = a ^ b
34+
return a, b
35+
36+
37+
if __name__ == "__main__":
38+
import doctest
39+
40+
doctest.testmod()

0 commit comments

Comments
 (0)