From 7f6082004e4ba3b71e766132d0676302d48f0a39 Mon Sep 17 00:00:00 2001 From: Legend015 Date: Fri, 6 Oct 2023 13:26:28 +0530 Subject: [PATCH 1/4] added a code to update a bit --- bit_manipulation/update_bit.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 bit_manipulation/update_bit.py diff --git a/bit_manipulation/update_bit.py b/bit_manipulation/update_bit.py new file mode 100644 index 000000000000..34edaa33b17d --- /dev/null +++ b/bit_manipulation/update_bit.py @@ -0,0 +1,28 @@ +def update_bit(n: int, pos: int, value: int) -> int: + ''' + It is a program to update a bit at given position + + Details:update the bit at position pos of the + number n by the value provided to it. + and return updated integer. + + >>> update_bit(5,0,0) #0b100 + 4 + >>> update_bit(10,1,0) #0b1000 + 8 + >>> update_bit(15,3,0) #0b0111 + 7 + >>> update_bit(5,1,1) #70b111 + 7 + >>> update_bit(10,0,1) #0b1011 + 11 + ''' + + mask = ~(1 << pos) + n = n & mask + return n | (value << pos) + +if __name__ == "__main__": + import doctest + + doctest.testmod() \ No newline at end of file From c1a52b40abe6b156315d71220b11be0e9d6d0d09 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 6 Oct 2023 08:22:12 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- bit_manipulation/update_bit.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bit_manipulation/update_bit.py b/bit_manipulation/update_bit.py index 34edaa33b17d..9eaa6ff2282a 100644 --- a/bit_manipulation/update_bit.py +++ b/bit_manipulation/update_bit.py @@ -1,5 +1,5 @@ def update_bit(n: int, pos: int, value: int) -> int: - ''' + """ It is a program to update a bit at given position Details:update the bit at position pos of the @@ -16,13 +16,14 @@ def update_bit(n: int, pos: int, value: int) -> int: 7 >>> update_bit(10,0,1) #0b1011 11 - ''' + """ mask = ~(1 << pos) n = n & mask return n | (value << pos) + if __name__ == "__main__": import doctest - doctest.testmod() \ No newline at end of file + doctest.testmod() From 3f375be2f19fd67eff0dcae2cf47181277b2323d Mon Sep 17 00:00:00 2001 From: Legend015 <146431311+Legend015@users.noreply.github.com> Date: Fri, 6 Oct 2023 13:59:57 +0530 Subject: [PATCH 3/4] modify update_bit.py --- bit_manipulation/update_bit.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bit_manipulation/update_bit.py b/bit_manipulation/update_bit.py index 9eaa6ff2282a..9bd310b18483 100644 --- a/bit_manipulation/update_bit.py +++ b/bit_manipulation/update_bit.py @@ -1,9 +1,9 @@ -def update_bit(n: int, pos: int, value: int) -> int: +def update_bit(number: int, position: int, value: int) -> int: """ It is a program to update a bit at given position - Details:update the bit at position pos of the - number n by the value provided to it. + Details:update the bit at position of the + number by the value provided to it. and return updated integer. >>> update_bit(5,0,0) #0b100 @@ -18,9 +18,9 @@ def update_bit(n: int, pos: int, value: int) -> int: 11 """ - mask = ~(1 << pos) - n = n & mask - return n | (value << pos) + mask = ~(1 << position) + number = number & mask + return number | (value << position) if __name__ == "__main__": From f32bde37d980950af55f2a5cf43e2ea8a1978aec Mon Sep 17 00:00:00 2001 From: cclauss Date: Tue, 15 Sep 2026 12:03:23 +0000 Subject: [PATCH 4/4] updating DIRECTORY.md --- DIRECTORY.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index d6ceb04a62eb..ae1a8564c774 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -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) @@ -105,9 +106,13 @@ * [Rotate Bits](bit_manipulation/rotate_bits.py) * [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py) * [Swap All Odd And Even Bits](bit_manipulation/swap_all_odd_and_even_bits.py) + * [Update Bit](bit_manipulation/update_bit.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) @@ -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) @@ -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) @@ -198,6 +205,9 @@ ## [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) @@ -205,6 +215,7 @@ * [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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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)