Skip to content

Commit af3f615

Browse files
authored
Merge branch 'master' into master
2 parents 2f853d1 + bc1f8a8 commit af3f615

55 files changed

Lines changed: 4630 additions & 2877 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: 21 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,8 +262,10 @@
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)
@@ -303,6 +305,7 @@
303305
* [Mirror Binary Tree](data_structures/binary_tree/mirror_binary_tree.py)
304306
* [Non Recursive Segment Tree](data_structures/binary_tree/non_recursive_segment_tree.py)
305307
* [Number Of Possible Binary Trees](data_structures/binary_tree/number_of_possible_binary_trees.py)
308+
* [Persistent Segment Tree](data_structures/binary_tree/persistent_segment_tree.py)
306309
* [Red Black Tree](data_structures/binary_tree/red_black_tree.py)
307310
* [Segment Tree](data_structures/binary_tree/segment_tree.py)
308311
* [Segment Tree Other](data_structures/binary_tree/segment_tree_other.py)
@@ -470,7 +473,6 @@
470473
* [Floyd Warshall](dynamic_programming/floyd_warshall.py)
471474
* [Integer Partition](dynamic_programming/integer_partition.py)
472475
* [Iterating Through Submasks](dynamic_programming/iterating_through_submasks.py)
473-
* [K Means Clustering Tensorflow](dynamic_programming/k_means_clustering_tensorflow.py)
474476
* [Knapsack](dynamic_programming/knapsack.py)
475477
* [Largest Divisible Subset](dynamic_programming/largest_divisible_subset.py)
476478
* [Longest Common Subsequence](dynamic_programming/longest_common_subsequence.py)
@@ -479,6 +481,7 @@
479481
* [Longest Increasing Subsequence Iterative](dynamic_programming/longest_increasing_subsequence_iterative.py)
480482
* [Longest Increasing Subsequence O Nlogn](dynamic_programming/longest_increasing_subsequence_o_nlogn.py)
481483
* [Longest Palindromic Subsequence](dynamic_programming/longest_palindromic_subsequence.py)
484+
* [Longest Repeating Subsequence](dynamic_programming/longest_repeating_subsequence.py)
482485
* [Matrix Chain Multiplication](dynamic_programming/matrix_chain_multiplication.py)
483486
* [Matrix Chain Order](dynamic_programming/matrix_chain_order.py)
484487
* [Max Non Adjacent Sum](dynamic_programming/max_non_adjacent_sum.py)
@@ -540,12 +543,15 @@
540543
* [Test Send File](file_transfer/tests/test_send_file.py)
541544

542545
## [Financial](financial)
546+
* [Annuity Due Future Value](financial/annuity_due_future_value.py)
543547
* [Equated Monthly Installments](financial/equated_monthly_installments.py)
544548
* [Expected Shortfall](financial/expected_shortfall.py)
545549
* [Exponential Moving Average](financial/exponential_moving_average.py)
550+
* [Fractional Differentiation](financial/fractional_differentiation.py)
546551
* [Interest](financial/interest.py)
547552
* [Kelly Criterion](financial/kelly_criterion.py)
548553
* [Macaulay Duration](financial/macaulay_duration.py)
554+
* [Ordinary Annuity Future Value](financial/ordinary_annuity_future_value.py)
549555
* [Present Value](financial/present_value.py)
550556
* [Price Plus Tax](financial/price_plus_tax.py)
551557
* [Sharpe Ratio](financial/sharpe_ratio.py)
@@ -629,6 +635,7 @@
629635
* [Dijkstra Binary Grid](graphs/dijkstra_binary_grid.py)
630636
* [Dinic](graphs/dinic.py)
631637
* [Directed And Undirected Weighted Graph](graphs/directed_and_undirected_weighted_graph.py)
638+
* [Edmonds Blossom Algorithm](graphs/edmonds_blossom_algorithm.py)
632639
* [Edmonds Karp Multiple Source And Sink](graphs/edmonds_karp_multiple_source_and_sink.py)
633640
* [Eulerian Path And Circuit For Undirected Graph](graphs/eulerian_path_and_circuit_for_undirected_graph.py)
634641
* [Even Tree](graphs/even_tree.py)
@@ -638,7 +645,9 @@
638645
* [Gale Shapley Bigraph](graphs/gale_shapley_bigraph.py)
639646
* [Graph Adjacency List](graphs/graph_adjacency_list.py)
640647
* [Graph Adjacency Matrix](graphs/graph_adjacency_matrix.py)
648+
* [Graph Centrality](graphs/graph_centrality.py)
641649
* [Graph List](graphs/graph_list.py)
650+
* [Graph Peripherality](graphs/graph_peripherality.py)
642651
* [Graphs Floyd Warshall](graphs/graphs_floyd_warshall.py)
643652
* [Greedy Best First](graphs/greedy_best_first.py)
644653
* [Greedy Min Vertex Cover](graphs/greedy_min_vertex_cover.py)
@@ -664,13 +673,15 @@
664673
* [Strongly Connected Components](graphs/strongly_connected_components.py)
665674
* [Tarjans Scc](graphs/tarjans_scc.py)
666675
* Tests
676+
* [Test Edmonds Blossom Algorithm](graphs/tests/test_edmonds_blossom_algorithm.py)
667677
* [Test Graphs Floyd Warshall](graphs/tests/test_graphs_floyd_warshall.py)
668678
* [Test Johnson](graphs/tests/test_johnson.py)
669679
* [Test Min Spanning Tree Kruskal](graphs/tests/test_min_spanning_tree_kruskal.py)
670680
* [Test Min Spanning Tree Prim](graphs/tests/test_min_spanning_tree_prim.py)
671681
* [Travelling Salesman Problem](graphs/travelling_salesman_problem.py)
672682

673683
## [Greedy Methods](greedy_methods)
684+
* [Activity Selection](greedy_methods/activity_selection.py)
674685
* [Best Time To Buy And Sell Stock](greedy_methods/best_time_to_buy_and_sell_stock.py)
675686
* [Fractional Cover Problem](greedy_methods/fractional_cover_problem.py)
676687
* [Fractional Knapsack](greedy_methods/fractional_knapsack.py)
@@ -754,8 +765,6 @@
754765
* [Local Weighted Learning](machine_learning/local_weighted_learning/local_weighted_learning.py)
755766
* [Logistic Regression](machine_learning/logistic_regression.py)
756767
* [Loss Functions](machine_learning/loss_functions.py)
757-
* Lstm
758-
* [Lstm Prediction](machine_learning/lstm/lstm_prediction.py)
759768
* [Mab](machine_learning/mab.py)
760769
* [Mean Shift](machine_learning/mean_shift.py)
761770
* [Mfcc](machine_learning/mfcc.py)
@@ -885,6 +894,7 @@
885894
* [Nevilles Method](maths/numerical_analysis/nevilles_method.py)
886895
* [Newton Forward Interpolation](maths/numerical_analysis/newton_forward_interpolation.py)
887896
* [Newton Raphson](maths/numerical_analysis/newton_raphson.py)
897+
* [Nth Root](maths/numerical_analysis/nth_root.py)
888898
* [Numerical Integration](maths/numerical_analysis/numerical_integration.py)
889899
* [Proper Fractions](maths/numerical_analysis/proper_fractions.py)
890900
* [Runge Kutta](maths/numerical_analysis/runge_kutta.py)
@@ -960,6 +970,7 @@
960970
* [Happy Number](maths/special_numbers/happy_number.py)
961971
* [Harshad Numbers](maths/special_numbers/harshad_numbers.py)
962972
* [Hexagonal Number](maths/special_numbers/hexagonal_number.py)
973+
* [Jacobsthal Number](maths/special_numbers/jacobsthal_number.py)
963974
* [Kaprekar Constant](maths/special_numbers/kaprekar_constant.py)
964975
* [Kaprekar Number](maths/special_numbers/kaprekar_number.py)
965976
* [Krishnamurthy Number](maths/special_numbers/krishnamurthy_number.py)
@@ -1019,6 +1030,7 @@
10191030
* [Spiral Print](matrix/spiral_print.py)
10201031
* Tests
10211032
* [Test Matrix Operation](matrix/tests/test_matrix_operation.py)
1033+
* [Transitive Closure](matrix/transitive_closure.py)
10221034
* [Validate Sudoku Board](matrix/validate_sudoku_board.py)
10231035

10241036
## [Networking Flow](networking_flow)
@@ -1043,7 +1055,7 @@
10431055
* [Swish](neural_network/activation_functions/swish.py)
10441056
* [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py)
10451057
* [Convolution Neural Network](neural_network/convolution_neural_network.py)
1046-
* [Input Data](neural_network/input_data.py)
1058+
* [Lstm](neural_network/lstm.py)
10471059
* Optimizers
10481060
* [Adagrad](neural_network/optimizers/adagrad.py)
10491061
* [Adam Optimizer](neural_network/optimizers/adam_optimizer.py)
@@ -1052,6 +1064,7 @@
10521064
* [Nesterov Accelerated Sgd](neural_network/optimizers/nesterov_accelerated_sgd.py)
10531065
* [Perceptron](neural_network/perceptron.py)
10541066
* [Simple Neural Network](neural_network/simple_neural_network.py)
1067+
* [Sliding Window Attention](neural_network/sliding_window_attention.py)
10551068
* [Two Hidden Layers Neural Network](neural_network/two_hidden_layers_neural_network.py)
10561069

10571070
## [Other](other)
@@ -1592,9 +1605,11 @@
15921605
* [Knuth Morris Pratt](strings/knuth_morris_pratt.py)
15931606
* [Largest Smallest Words](strings/largest_smallest_words.py)
15941607
* [Levenshtein Distance](strings/levenshtein_distance.py)
1608+
* [Longest Word In Sentence](strings/longest_word_in_sentence.py)
15951609
* [Lower](strings/lower.py)
15961610
* [Manacher](strings/manacher.py)
15971611
* [Min Cost String Conversion](strings/min_cost_string_conversion.py)
1612+
* [Min Window Substring](strings/min_window_substring.py)
15981613
* [Naive String Search](strings/naive_string_search.py)
15991614
* [Ngram](strings/ngram.py)
16001615
* [Palindrome](strings/palindrome.py)
@@ -1606,6 +1621,7 @@
16061621
* [Reverse Words](strings/reverse_words.py)
16071622
* [Snake Case To Camel Pascal Case](strings/snake_case_to_camel_pascal_case.py)
16081623
* [Split](strings/split.py)
1624+
* [String Is Valid Number](strings/string_is_valid_number.py)
16091625
* [String Switch Case](strings/string_switch_case.py)
16101626
* [Strip](strings/strip.py)
16111627
* [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()

‎computer_vision/cnn_classification.py‎

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

0 commit comments

Comments
 (0)