Skip to content

Commit 86f4729

Browse files
authored
Merge branch 'master' into types/reverse-selection-sort
2 parents 94d7867 + 1d64d4c commit 86f4729

52 files changed

Lines changed: 3640 additions & 2873 deletions

Some content is hidden

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

‎.github/workflows/build.yml‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ 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
3125
# opencv-python is gated out on 3.14t (no cp314t wheel yet), so skip the
@@ -41,16 +35,12 @@ jobs:
4135
# single file that imports it (quantum/q_fourier_transform.py) is skipped too.
4236
run: uv run --with=pytest-run-parallel pytest
4337
--iterations=8 --parallel-threads=auto --ignore-gil-enabled
44-
--ignore=computer_vision/cnn_classification.py
4538
--ignore=computer_vision/flip_augmentation.py
4639
--ignore=computer_vision/harris_corner.py
4740
--ignore=computer_vision/mosaic_augmentation.py
4841
--ignore=data_compression/peak_signal_to_noise_ratio.py
4942
--ignore=digital_image_processing/
5043
--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
5444
--ignore=project_euler/
5545
--ignore=quantum/q_fourier_transform.py
5646
--ignore=scripts/validate_solutions.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

‎DIRECTORY.md‎

Lines changed: 20 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,22 @@
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 Sorted](data_structures/arrays/merge_sorted.py)
270273
* [Monotonic Array](data_structures/arrays/monotonic_array.py)
271274
* [Pairs With Given Sum](data_structures/arrays/pairs_with_given_sum.py)
272275
* [Pairwise Iteration](data_structures/arrays/pairwise_iteration.py)
273276
* [Permutations](data_structures/arrays/permutations.py)
274277
* [Prefix Sum](data_structures/arrays/prefix_sum.py)
275278
* [Product Sum](data_structures/arrays/product_sum.py)
276279
* [Rotate Array](data_structures/arrays/rotate_array.py)
280+
* [Set Matrix Zeroes](data_structures/arrays/set_matrix_zeroes.py)
277281
* [Sparse Table](data_structures/arrays/sparse_table.py)
278282
* [Sudoku Solver](data_structures/arrays/sudoku_solver.py)
279283
* Binary Tree
@@ -303,6 +307,7 @@
303307
* [Mirror Binary Tree](data_structures/binary_tree/mirror_binary_tree.py)
304308
* [Non Recursive Segment Tree](data_structures/binary_tree/non_recursive_segment_tree.py)
305309
* [Number Of Possible Binary Trees](data_structures/binary_tree/number_of_possible_binary_trees.py)
310+
* [Persistent Segment Tree](data_structures/binary_tree/persistent_segment_tree.py)
306311
* [Red Black Tree](data_structures/binary_tree/red_black_tree.py)
307312
* [Segment Tree](data_structures/binary_tree/segment_tree.py)
308313
* [Segment Tree Other](data_structures/binary_tree/segment_tree_other.py)
@@ -470,7 +475,6 @@
470475
* [Floyd Warshall](dynamic_programming/floyd_warshall.py)
471476
* [Integer Partition](dynamic_programming/integer_partition.py)
472477
* [Iterating Through Submasks](dynamic_programming/iterating_through_submasks.py)
473-
* [K Means Clustering Tensorflow](dynamic_programming/k_means_clustering_tensorflow.py)
474478
* [Knapsack](dynamic_programming/knapsack.py)
475479
* [Largest Divisible Subset](dynamic_programming/largest_divisible_subset.py)
476480
* [Longest Common Subsequence](dynamic_programming/longest_common_subsequence.py)
@@ -479,6 +483,7 @@
479483
* [Longest Increasing Subsequence Iterative](dynamic_programming/longest_increasing_subsequence_iterative.py)
480484
* [Longest Increasing Subsequence O Nlogn](dynamic_programming/longest_increasing_subsequence_o_nlogn.py)
481485
* [Longest Palindromic Subsequence](dynamic_programming/longest_palindromic_subsequence.py)
486+
* [Longest Repeating Subsequence](dynamic_programming/longest_repeating_subsequence.py)
482487
* [Matrix Chain Multiplication](dynamic_programming/matrix_chain_multiplication.py)
483488
* [Matrix Chain Order](dynamic_programming/matrix_chain_order.py)
484489
* [Max Non Adjacent Sum](dynamic_programming/max_non_adjacent_sum.py)
@@ -540,13 +545,15 @@
540545
* [Test Send File](file_transfer/tests/test_send_file.py)
541546

542547
## [Financial](financial)
548+
* [Annuity Due Future Value](financial/annuity_due_future_value.py)
543549
* [Equated Monthly Installments](financial/equated_monthly_installments.py)
544550
* [Expected Shortfall](financial/expected_shortfall.py)
545551
* [Exponential Moving Average](financial/exponential_moving_average.py)
546552
* [Fractional Differentiation](financial/fractional_differentiation.py)
547553
* [Interest](financial/interest.py)
548554
* [Kelly Criterion](financial/kelly_criterion.py)
549555
* [Macaulay Duration](financial/macaulay_duration.py)
556+
* [Ordinary Annuity Future Value](financial/ordinary_annuity_future_value.py)
550557
* [Present Value](financial/present_value.py)
551558
* [Price Plus Tax](financial/price_plus_tax.py)
552559
* [Sharpe Ratio](financial/sharpe_ratio.py)
@@ -630,6 +637,7 @@
630637
* [Dijkstra Binary Grid](graphs/dijkstra_binary_grid.py)
631638
* [Dinic](graphs/dinic.py)
632639
* [Directed And Undirected Weighted Graph](graphs/directed_and_undirected_weighted_graph.py)
640+
* [Edmonds Blossom Algorithm](graphs/edmonds_blossom_algorithm.py)
633641
* [Edmonds Karp Multiple Source And Sink](graphs/edmonds_karp_multiple_source_and_sink.py)
634642
* [Eulerian Path And Circuit For Undirected Graph](graphs/eulerian_path_and_circuit_for_undirected_graph.py)
635643
* [Even Tree](graphs/even_tree.py)
@@ -639,7 +647,9 @@
639647
* [Gale Shapley Bigraph](graphs/gale_shapley_bigraph.py)
640648
* [Graph Adjacency List](graphs/graph_adjacency_list.py)
641649
* [Graph Adjacency Matrix](graphs/graph_adjacency_matrix.py)
650+
* [Graph Centrality](graphs/graph_centrality.py)
642651
* [Graph List](graphs/graph_list.py)
652+
* [Graph Peripherality](graphs/graph_peripherality.py)
643653
* [Graphs Floyd Warshall](graphs/graphs_floyd_warshall.py)
644654
* [Greedy Best First](graphs/greedy_best_first.py)
645655
* [Greedy Min Vertex Cover](graphs/greedy_min_vertex_cover.py)
@@ -665,6 +675,7 @@
665675
* [Strongly Connected Components](graphs/strongly_connected_components.py)
666676
* [Tarjans Scc](graphs/tarjans_scc.py)
667677
* Tests
678+
* [Test Edmonds Blossom Algorithm](graphs/tests/test_edmonds_blossom_algorithm.py)
668679
* [Test Graphs Floyd Warshall](graphs/tests/test_graphs_floyd_warshall.py)
669680
* [Test Johnson](graphs/tests/test_johnson.py)
670681
* [Test Min Spanning Tree Kruskal](graphs/tests/test_min_spanning_tree_kruskal.py)
@@ -694,6 +705,7 @@
694705
* [Enigma Machine](hashes/enigma_machine.py)
695706
* [Fletcher16](hashes/fletcher16.py)
696707
* [Hamming Code](hashes/hamming_code.py)
708+
* [Jenkins One At A Time](hashes/jenkins_one_at_a_time.py)
697709
* [Luhn](hashes/luhn.py)
698710
* [Md5](hashes/md5.py)
699711
* [Sdbm](hashes/sdbm.py)
@@ -756,8 +768,6 @@
756768
* [Local Weighted Learning](machine_learning/local_weighted_learning/local_weighted_learning.py)
757769
* [Logistic Regression](machine_learning/logistic_regression.py)
758770
* [Loss Functions](machine_learning/loss_functions.py)
759-
* Lstm
760-
* [Lstm Prediction](machine_learning/lstm/lstm_prediction.py)
761771
* [Mab](machine_learning/mab.py)
762772
* [Mean Shift](machine_learning/mean_shift.py)
763773
* [Mfcc](machine_learning/mfcc.py)
@@ -963,6 +973,7 @@
963973
* [Happy Number](maths/special_numbers/happy_number.py)
964974
* [Harshad Numbers](maths/special_numbers/harshad_numbers.py)
965975
* [Hexagonal Number](maths/special_numbers/hexagonal_number.py)
976+
* [Jacobsthal Number](maths/special_numbers/jacobsthal_number.py)
966977
* [Kaprekar Constant](maths/special_numbers/kaprekar_constant.py)
967978
* [Kaprekar Number](maths/special_numbers/kaprekar_number.py)
968979
* [Krishnamurthy Number](maths/special_numbers/krishnamurthy_number.py)
@@ -1019,9 +1030,11 @@
10191030
* [Rotate Matrix](matrix/rotate_matrix.py)
10201031
* [Searching In Sorted Matrix](matrix/searching_in_sorted_matrix.py)
10211032
* [Sherman Morrison](matrix/sherman_morrison.py)
1033+
* [Similar Matrices](matrix/similar_matrices.py)
10221034
* [Spiral Print](matrix/spiral_print.py)
10231035
* Tests
10241036
* [Test Matrix Operation](matrix/tests/test_matrix_operation.py)
1037+
* [Transitive Closure](matrix/transitive_closure.py)
10251038
* [Validate Sudoku Board](matrix/validate_sudoku_board.py)
10261039

10271040
## [Networking Flow](networking_flow)
@@ -1046,7 +1059,7 @@
10461059
* [Swish](neural_network/activation_functions/swish.py)
10471060
* [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py)
10481061
* [Convolution Neural Network](neural_network/convolution_neural_network.py)
1049-
* [Input Data](neural_network/input_data.py)
1062+
* [Lstm](neural_network/lstm.py)
10501063
* Optimizers
10511064
* [Adagrad](neural_network/optimizers/adagrad.py)
10521065
* [Adam Optimizer](neural_network/optimizers/adam_optimizer.py)
@@ -1055,6 +1068,7 @@
10551068
* [Nesterov Accelerated Sgd](neural_network/optimizers/nesterov_accelerated_sgd.py)
10561069
* [Perceptron](neural_network/perceptron.py)
10571070
* [Simple Neural Network](neural_network/simple_neural_network.py)
1071+
* [Sliding Window Attention](neural_network/sliding_window_attention.py)
10581072
* [Two Hidden Layers Neural Network](neural_network/two_hidden_layers_neural_network.py)
10591073

10601074
## [Other](other)
@@ -1599,6 +1613,7 @@
15991613
* [Lower](strings/lower.py)
16001614
* [Manacher](strings/manacher.py)
16011615
* [Min Cost String Conversion](strings/min_cost_string_conversion.py)
1616+
* [Min Window Substring](strings/min_window_substring.py)
16021617
* [Naive String Search](strings/naive_string_search.py)
16031618
* [Ngram](strings/ngram.py)
16041619
* [Palindrome](strings/palindrome.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()

‎computer_vision/cnn_classification.py‎

Lines changed: 0 additions & 99 deletions
This file was deleted.

0 commit comments

Comments
 (0)