Skip to content

Commit 8a0f9e3

Browse files
authored
Merge branch 'master' into diffraction
2 parents ff277e7 + 0a72d14 commit 8a0f9e3

90 files changed

Lines changed: 4839 additions & 3699 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/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

‎.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: 27 additions & 5 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)
@@ -262,18 +262,24 @@
262262

263263
## [Data Structures](data_structures)
264264
* Arrays
265+
* [Dynamic Array](data_structures/arrays/dynamic_array.py)
265266
* [Equilibrium Index In Array](data_structures/arrays/equilibrium_index_in_array.py)
266267
* [Find Triplets With 0 Sum](data_structures/arrays/find_triplets_with_0_sum.py)
268+
* [Gas Station](data_structures/arrays/gas_station.py)
267269
* [Index 2D Array In 1D](data_structures/arrays/index_2d_array_in_1d.py)
268270
* [Kth Largest Element](data_structures/arrays/kth_largest_element.py)
269271
* [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)
270274
* [Monotonic Array](data_structures/arrays/monotonic_array.py)
271275
* [Pairs With Given Sum](data_structures/arrays/pairs_with_given_sum.py)
272276
* [Pairwise Iteration](data_structures/arrays/pairwise_iteration.py)
273277
* [Permutations](data_structures/arrays/permutations.py)
274278
* [Prefix Sum](data_structures/arrays/prefix_sum.py)
275279
* [Product Sum](data_structures/arrays/product_sum.py)
280+
* [Reverse Array](data_structures/arrays/reverse_array.py)
276281
* [Rotate Array](data_structures/arrays/rotate_array.py)
282+
* [Set Matrix Zeroes](data_structures/arrays/set_matrix_zeroes.py)
277283
* [Sparse Table](data_structures/arrays/sparse_table.py)
278284
* [Sudoku Solver](data_structures/arrays/sudoku_solver.py)
279285
* Binary Tree
@@ -303,6 +309,7 @@
303309
* [Mirror Binary Tree](data_structures/binary_tree/mirror_binary_tree.py)
304310
* [Non Recursive Segment Tree](data_structures/binary_tree/non_recursive_segment_tree.py)
305311
* [Number Of Possible Binary Trees](data_structures/binary_tree/number_of_possible_binary_trees.py)
312+
* [Persistent Segment Tree](data_structures/binary_tree/persistent_segment_tree.py)
306313
* [Red Black Tree](data_structures/binary_tree/red_black_tree.py)
307314
* [Segment Tree](data_structures/binary_tree/segment_tree.py)
308315
* [Segment Tree Other](data_structures/binary_tree/segment_tree_other.py)
@@ -470,7 +477,6 @@
470477
* [Floyd Warshall](dynamic_programming/floyd_warshall.py)
471478
* [Integer Partition](dynamic_programming/integer_partition.py)
472479
* [Iterating Through Submasks](dynamic_programming/iterating_through_submasks.py)
473-
* [K Means Clustering Tensorflow](dynamic_programming/k_means_clustering_tensorflow.py)
474480
* [Knapsack](dynamic_programming/knapsack.py)
475481
* [Largest Divisible Subset](dynamic_programming/largest_divisible_subset.py)
476482
* [Longest Common Subsequence](dynamic_programming/longest_common_subsequence.py)
@@ -479,6 +485,7 @@
479485
* [Longest Increasing Subsequence Iterative](dynamic_programming/longest_increasing_subsequence_iterative.py)
480486
* [Longest Increasing Subsequence O Nlogn](dynamic_programming/longest_increasing_subsequence_o_nlogn.py)
481487
* [Longest Palindromic Subsequence](dynamic_programming/longest_palindromic_subsequence.py)
488+
* [Longest Repeating Subsequence](dynamic_programming/longest_repeating_subsequence.py)
482489
* [Matrix Chain Multiplication](dynamic_programming/matrix_chain_multiplication.py)
483490
* [Matrix Chain Order](dynamic_programming/matrix_chain_order.py)
484491
* [Max Non Adjacent Sum](dynamic_programming/max_non_adjacent_sum.py)
@@ -540,12 +547,15 @@
540547
* [Test Send File](file_transfer/tests/test_send_file.py)
541548

542549
## [Financial](financial)
550+
* [Annuity Due Future Value](financial/annuity_due_future_value.py)
543551
* [Equated Monthly Installments](financial/equated_monthly_installments.py)
544552
* [Expected Shortfall](financial/expected_shortfall.py)
545553
* [Exponential Moving Average](financial/exponential_moving_average.py)
554+
* [Fractional Differentiation](financial/fractional_differentiation.py)
546555
* [Interest](financial/interest.py)
547556
* [Kelly Criterion](financial/kelly_criterion.py)
548557
* [Macaulay Duration](financial/macaulay_duration.py)
558+
* [Ordinary Annuity Future Value](financial/ordinary_annuity_future_value.py)
549559
* [Present Value](financial/present_value.py)
550560
* [Price Plus Tax](financial/price_plus_tax.py)
551561
* [Sharpe Ratio](financial/sharpe_ratio.py)
@@ -629,6 +639,7 @@
629639
* [Dijkstra Binary Grid](graphs/dijkstra_binary_grid.py)
630640
* [Dinic](graphs/dinic.py)
631641
* [Directed And Undirected Weighted Graph](graphs/directed_and_undirected_weighted_graph.py)
642+
* [Edmonds Blossom Algorithm](graphs/edmonds_blossom_algorithm.py)
632643
* [Edmonds Karp Multiple Source And Sink](graphs/edmonds_karp_multiple_source_and_sink.py)
633644
* [Eulerian Path And Circuit For Undirected Graph](graphs/eulerian_path_and_circuit_for_undirected_graph.py)
634645
* [Even Tree](graphs/even_tree.py)
@@ -638,7 +649,9 @@
638649
* [Gale Shapley Bigraph](graphs/gale_shapley_bigraph.py)
639650
* [Graph Adjacency List](graphs/graph_adjacency_list.py)
640651
* [Graph Adjacency Matrix](graphs/graph_adjacency_matrix.py)
652+
* [Graph Centrality](graphs/graph_centrality.py)
641653
* [Graph List](graphs/graph_list.py)
654+
* [Graph Peripherality](graphs/graph_peripherality.py)
642655
* [Graphs Floyd Warshall](graphs/graphs_floyd_warshall.py)
643656
* [Greedy Best First](graphs/greedy_best_first.py)
644657
* [Greedy Min Vertex Cover](graphs/greedy_min_vertex_cover.py)
@@ -664,13 +677,15 @@
664677
* [Strongly Connected Components](graphs/strongly_connected_components.py)
665678
* [Tarjans Scc](graphs/tarjans_scc.py)
666679
* Tests
680+
* [Test Edmonds Blossom Algorithm](graphs/tests/test_edmonds_blossom_algorithm.py)
667681
* [Test Graphs Floyd Warshall](graphs/tests/test_graphs_floyd_warshall.py)
668682
* [Test Johnson](graphs/tests/test_johnson.py)
669683
* [Test Min Spanning Tree Kruskal](graphs/tests/test_min_spanning_tree_kruskal.py)
670684
* [Test Min Spanning Tree Prim](graphs/tests/test_min_spanning_tree_prim.py)
671685
* [Travelling Salesman Problem](graphs/travelling_salesman_problem.py)
672686

673687
## [Greedy Methods](greedy_methods)
688+
* [Activity Selection](greedy_methods/activity_selection.py)
674689
* [Best Time To Buy And Sell Stock](greedy_methods/best_time_to_buy_and_sell_stock.py)
675690
* [Fractional Cover Problem](greedy_methods/fractional_cover_problem.py)
676691
* [Fractional Knapsack](greedy_methods/fractional_knapsack.py)
@@ -692,6 +707,7 @@
692707
* [Enigma Machine](hashes/enigma_machine.py)
693708
* [Fletcher16](hashes/fletcher16.py)
694709
* [Hamming Code](hashes/hamming_code.py)
710+
* [Jenkins One At A Time](hashes/jenkins_one_at_a_time.py)
695711
* [Luhn](hashes/luhn.py)
696712
* [Md5](hashes/md5.py)
697713
* [Sdbm](hashes/sdbm.py)
@@ -754,8 +770,6 @@
754770
* [Local Weighted Learning](machine_learning/local_weighted_learning/local_weighted_learning.py)
755771
* [Logistic Regression](machine_learning/logistic_regression.py)
756772
* [Loss Functions](machine_learning/loss_functions.py)
757-
* Lstm
758-
* [Lstm Prediction](machine_learning/lstm/lstm_prediction.py)
759773
* [Mab](machine_learning/mab.py)
760774
* [Mean Shift](machine_learning/mean_shift.py)
761775
* [Mfcc](machine_learning/mfcc.py)
@@ -885,6 +899,7 @@
885899
* [Nevilles Method](maths/numerical_analysis/nevilles_method.py)
886900
* [Newton Forward Interpolation](maths/numerical_analysis/newton_forward_interpolation.py)
887901
* [Newton Raphson](maths/numerical_analysis/newton_raphson.py)
902+
* [Nth Root](maths/numerical_analysis/nth_root.py)
888903
* [Numerical Integration](maths/numerical_analysis/numerical_integration.py)
889904
* [Proper Fractions](maths/numerical_analysis/proper_fractions.py)
890905
* [Runge Kutta](maths/numerical_analysis/runge_kutta.py)
@@ -960,6 +975,7 @@
960975
* [Happy Number](maths/special_numbers/happy_number.py)
961976
* [Harshad Numbers](maths/special_numbers/harshad_numbers.py)
962977
* [Hexagonal Number](maths/special_numbers/hexagonal_number.py)
978+
* [Jacobsthal Number](maths/special_numbers/jacobsthal_number.py)
963979
* [Kaprekar Constant](maths/special_numbers/kaprekar_constant.py)
964980
* [Kaprekar Number](maths/special_numbers/kaprekar_number.py)
965981
* [Krishnamurthy Number](maths/special_numbers/krishnamurthy_number.py)
@@ -1016,9 +1032,11 @@
10161032
* [Rotate Matrix](matrix/rotate_matrix.py)
10171033
* [Searching In Sorted Matrix](matrix/searching_in_sorted_matrix.py)
10181034
* [Sherman Morrison](matrix/sherman_morrison.py)
1035+
* [Similar Matrices](matrix/similar_matrices.py)
10191036
* [Spiral Print](matrix/spiral_print.py)
10201037
* Tests
10211038
* [Test Matrix Operation](matrix/tests/test_matrix_operation.py)
1039+
* [Transitive Closure](matrix/transitive_closure.py)
10221040
* [Validate Sudoku Board](matrix/validate_sudoku_board.py)
10231041

10241042
## [Networking Flow](networking_flow)
@@ -1043,7 +1061,7 @@
10431061
* [Swish](neural_network/activation_functions/swish.py)
10441062
* [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py)
10451063
* [Convolution Neural Network](neural_network/convolution_neural_network.py)
1046-
* [Input Data](neural_network/input_data.py)
1064+
* [Lstm](neural_network/lstm.py)
10471065
* Optimizers
10481066
* [Adagrad](neural_network/optimizers/adagrad.py)
10491067
* [Adam Optimizer](neural_network/optimizers/adam_optimizer.py)
@@ -1052,6 +1070,7 @@
10521070
* [Nesterov Accelerated Sgd](neural_network/optimizers/nesterov_accelerated_sgd.py)
10531071
* [Perceptron](neural_network/perceptron.py)
10541072
* [Simple Neural Network](neural_network/simple_neural_network.py)
1073+
* [Sliding Window Attention](neural_network/sliding_window_attention.py)
10551074
* [Two Hidden Layers Neural Network](neural_network/two_hidden_layers_neural_network.py)
10561075

10571076
## [Other](other)
@@ -1593,9 +1612,11 @@
15931612
* [Knuth Morris Pratt](strings/knuth_morris_pratt.py)
15941613
* [Largest Smallest Words](strings/largest_smallest_words.py)
15951614
* [Levenshtein Distance](strings/levenshtein_distance.py)
1615+
* [Longest Word In Sentence](strings/longest_word_in_sentence.py)
15961616
* [Lower](strings/lower.py)
15971617
* [Manacher](strings/manacher.py)
15981618
* [Min Cost String Conversion](strings/min_cost_string_conversion.py)
1619+
* [Min Window Substring](strings/min_window_substring.py)
15991620
* [Naive String Search](strings/naive_string_search.py)
16001621
* [Ngram](strings/ngram.py)
16011622
* [Palindrome](strings/palindrome.py)
@@ -1607,6 +1628,7 @@
16071628
* [Reverse Words](strings/reverse_words.py)
16081629
* [Snake Case To Camel Pascal Case](strings/snake_case_to_camel_pascal_case.py)
16091630
* [Split](strings/split.py)
1631+
* [String Is Valid Number](strings/string_is_valid_number.py)
16101632
* [String Switch Case](strings/string_switch_case.py)
16111633
* [Strip](strings/strip.py)
16121634
* [Suffix Automaton](strings/suffix_automaton.py)
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)