Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
* [Generate Parentheses Iterative](backtracking/generate_parentheses_iterative.py)
* [Hamiltonian Cycle](backtracking/hamiltonian_cycle.py)
* [Knight Tour](backtracking/knight_tour.py)
* [M Coloring Problem](backtracking/m_coloring_problem.py)
* [Match Word Pattern](backtracking/match_word_pattern.py)
* [Minimax](backtracking/minimax.py)
* [N Queens](backtracking/n_queens.py)
Expand Down Expand Up @@ -104,10 +105,14 @@
* [Reverse Bits](bit_manipulation/reverse_bits.py)
* [Rotate Bits](bit_manipulation/rotate_bits.py)
* [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py)
* [Single Number](bit_manipulation/single_number.py)
* [Swap All Odd And Even Bits](bit_manipulation/swap_all_odd_and_even_bits.py)

## [Blockchain](blockchain)
* [Diophantine Equation](blockchain/diophantine_equation.py)
* [Merkle Tree](blockchain/merkle_tree.py)
* [Simple Blockchain](blockchain/simple_blockchain.py)
* [Simple Proof Of Work](blockchain/simple_proof_of_work.py)

## [Boolean Algebra](boolean_algebra)
* [And Gate](boolean_algebra/and_gate.py)
Expand Down Expand Up @@ -166,6 +171,7 @@
* [Porta Cipher](ciphers/porta_cipher.py)
* [Rabin Miller](ciphers/rabin_miller.py)
* [Rail Fence Cipher](ciphers/rail_fence_cipher.py)
* [Rc4](ciphers/rc4.py)
* [Rot13](ciphers/rot13.py)
* [Rsa Cipher](ciphers/rsa_cipher.py)
* [Rsa Factorization](ciphers/rsa_factorization.py)
Expand All @@ -180,6 +186,7 @@
* [Vernam Cipher](ciphers/vernam_cipher.py)
* [Vigenere Cipher](ciphers/vigenere_cipher.py)
* [Xor Cipher](ciphers/xor_cipher.py)
* [Xtea](ciphers/xtea.py)

## [Computer Vision](computer_vision)
* [Cnn Classification](computer_vision/cnn_classification.py)
Expand All @@ -198,13 +205,17 @@
## [Conversions](conversions)
* [Astronomical Length Scale Conversion](conversions/astronomical_length_scale_conversion.py)
* [Binary To Decimal](conversions/binary_to_decimal.py)
* [Binary To Excess3](conversions/binary_to_excess3.py)
* [Binary To Gray](conversions/binary_to_gray.py)
* [Binary To Gray Code](conversions/binary_to_gray_code.py)
* [Binary To Hexadecimal](conversions/binary_to_hexadecimal.py)
* [Binary To Octal](conversions/binary_to_octal.py)
* [Convert Number To Words](conversions/convert_number_to_words.py)
* [Decimal To Any](conversions/decimal_to_any.py)
* [Decimal To Binary](conversions/decimal_to_binary.py)
* [Decimal To Hexadecimal](conversions/decimal_to_hexadecimal.py)
* [Decimal To Octal](conversions/decimal_to_octal.py)
* [Endianness](conversions/endianness.py)
* [Energy Conversions](conversions/energy_conversions.py)
* [Excel Title To Column](conversions/excel_title_to_column.py)
* [Hex To Bin](conversions/hex_to_bin.py)
Expand Down Expand Up @@ -689,6 +700,7 @@
* [Astar](machine_learning/astar.py)
* [Automatic Differentiation](machine_learning/automatic_differentiation.py)
* [Data Transformations](machine_learning/data_transformations.py)
* [Dbscan](machine_learning/dbscan.py)
* [Decision Tree](machine_learning/decision_tree.py)
* [Dimensionality Reduction](machine_learning/dimensionality_reduction.py)
* [Federated Averaging](machine_learning/federated_averaging.py)
Expand All @@ -712,15 +724,18 @@
* [Loss Functions](machine_learning/loss_functions.py)
* Lstm
* [Lstm Prediction](machine_learning/lstm/lstm_prediction.py)
* [Mean Shift](machine_learning/mean_shift.py)
* [Mfcc](machine_learning/mfcc.py)
* [Mini Batch Gradient Descent](machine_learning/mini_batch_gradient_descent.py)
* [Multilayer Perceptron Classifier](machine_learning/multilayer_perceptron_classifier.py)
* [Naive Bayes Text Classification](machine_learning/naive_bayes_text_classification.py)
* [Ordinary Least Squares Regression](machine_learning/ordinary_least_squares_regression.py)
* [Polynomial Regression](machine_learning/polynomial_regression.py)
* [Principle Component Analysis](machine_learning/principle_component_analysis.py)
* [Q Learning](machine_learning/q_learning.py)
* [Random Forest Classifier](machine_learning/random_forest_classifier.py)
* [Random Forest Regressor](machine_learning/random_forest_regressor.py)
* [Rmsprop](machine_learning/rmsprop.py)
* [Scoring Functions](machine_learning/scoring_functions.py)
* [Self Organizing Map](machine_learning/self_organizing_map.py)
* [Sequential Minimum Optimization](machine_learning/sequential_minimum_optimization.py)
Expand All @@ -737,6 +752,7 @@
* [Arc Length](maths/arc_length.py)
* [Area](maths/area.py)
* [Area Under Curve](maths/area_under_curve.py)
* [Autocorrelation](maths/autocorrelation.py)
* [Average Absolute Deviation](maths/average_absolute_deviation.py)
* [Average Mean](maths/average_mean.py)
* [Average Median](maths/average_median.py)
Expand Down Expand Up @@ -782,6 +798,7 @@
* [Fibonacci](maths/fibonacci.py)
* [Find Max](maths/find_max.py)
* [Find Min](maths/find_min.py)
* [First Fundamental Form](maths/first_fundamental_form.py)
* [Floor](maths/floor.py)
* [Gamma](maths/gamma.py)
* [Gaussian](maths/gaussian.py)
Expand Down Expand Up @@ -844,6 +861,7 @@
* [Square Root](maths/numerical_analysis/square_root.py)
* [Weierstrass Method](maths/numerical_analysis/weierstrass_method.py)
* [Odd Sieve](maths/odd_sieve.py)
* [Padovan Sequence](maths/padovan_sequence.py)
* [Pell Number](maths/pell_number.py)
* [Perfect Cube](maths/perfect_cube.py)
* [Perfect Number](maths/perfect_number.py)
Expand Down Expand Up @@ -873,6 +891,8 @@
* [Reverse Factorial Recursive](maths/reverse_factorial_recursive.py)
* [Segmented Sieve](maths/segmented_sieve.py)
* Series
* [Alternate Harmonic Series](maths/series/alternate_harmonic_series.py)
* [Alternating Harmonic Series](maths/series/alternating_harmonic_series.py)
* [Arithmetic](maths/series/arithmetic.py)
* [Geometric](maths/series/geometric.py)
* [Geometric Series](maths/series/geometric_series.py)
Expand Down Expand Up @@ -912,6 +932,7 @@
* [Polygonal Numbers](maths/special_numbers/polygonal_numbers.py)
* [Pronic Number](maths/special_numbers/pronic_number.py)
* [Proth Number](maths/special_numbers/proth_number.py)
* [Spy Number](maths/special_numbers/spy_number.py)
* [Triangular Numbers](maths/special_numbers/triangular_numbers.py)
* [Trimorphic Number](maths/special_numbers/trimorphic_number.py)
* [Ugly Numbers](maths/special_numbers/ugly_numbers.py)
Expand Down
30 changes: 30 additions & 0 deletions bit_manipulation/single_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
def single_number(nums: list[int]) -> int:
"""
Find the single number in an array where every other number appears twice.

Args:
nums: List of integers where every integer appears twice except for one.

Returns:
The single integer that appears once.

Example:
>>> single_number([4, 1, 2, 1, 2])
4
>>> single_number([2, 2, 1])
1
>>> single_number([1])
1
"""
result = 0
for num in nums:
result ^= num # Applying XOR operation
return result


if __name__ == "__main__":
# Test cases
print(single_number([4, 1, 2, 1, 2])) # Output: 4
print(single_number([2, 2, 1])) # Output: 1
print(single_number([1])) # Output: 1
print(single_number([5, 3, 5, 7, 3])) # Output: 7