From 0ea5c734e13e40fcefdea336bc5f735536f133a0 Mon Sep 17 00:00:00 2001 From: Souvik Ghosh <42302494+SouvikGhosh05@users.noreply.github.com> Date: Thu, 4 Nov 2021 01:54:50 +0530 Subject: [PATCH] sock_merchant.py: Matching socks by color (#5761) * Python file for finding number of pairs * updating DIRECTORY.md * fixed iterative_pair.py * further fixed with type casting * fixed naming conventions * further fixed with naming convention * documented done * build issue fixed * updating DIRECTORY.md * Revert "documented done" This reverts commit 3be15ca374f3ea3f01f725912dba59b939b058b5. * Update canny.py * Update test_digital_image_processing.py * Update sobel_filter.py * requirements.txt fixed * keras<2.7.0 * Update sock_merchant.py * doctest with black fixed * Update sock_merchant.py Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Christian Clauss --- DIRECTORY.md | 6 +++++- maths/sock_merchant.py | 20 ++++++++++++++++++++ requirements.txt | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 maths/sock_merchant.py diff --git a/DIRECTORY.md b/DIRECTORY.md index e70c0aab6..fd164c92e 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -39,6 +39,7 @@ * [Binary Xor Operator](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/binary_xor_operator.py) * [Count 1S Brian Kernighan Method](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/count_1s_brian_kernighan_method.py) * [Count Number Of One Bits](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/count_number_of_one_bits.py) + * [Gray Code Sequence](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/gray_code_sequence.py) * [Reverse Bits](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/reverse_bits.py) * [Single Bit Manipulation Operations](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/single_bit_manipulation_operations.py) @@ -63,7 +64,7 @@ * [Baconian Cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/baconian_cipher.py) * [Base16](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base16.py) * [Base32](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base32.py) - * [Base64 Encoding](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base64_encoding.py) + * [Base64](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base64.py) * [Base85](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base85.py) * [Beaufort Cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/beaufort_cipher.py) * [Bifid](https://github.com/TheAlgorithms/Python/blob/master/ciphers/bifid.py) @@ -219,6 +220,7 @@ * Filters * [Bilateral Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/bilateral_filter.py) * [Convolve](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/convolve.py) + * [Gabor Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/gabor_filter.py) * [Gaussian Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/gaussian_filter.py) * [Median Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/median_filter.py) * [Sobel Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/sobel_filter.py) @@ -511,6 +513,7 @@ * [Modular Exponential](https://github.com/TheAlgorithms/Python/blob/master/maths/modular_exponential.py) * [Monte Carlo](https://github.com/TheAlgorithms/Python/blob/master/maths/monte_carlo.py) * [Monte Carlo Dice](https://github.com/TheAlgorithms/Python/blob/master/maths/monte_carlo_dice.py) + * [Nevilles Method](https://github.com/TheAlgorithms/Python/blob/master/maths/nevilles_method.py) * [Newton Raphson](https://github.com/TheAlgorithms/Python/blob/master/maths/newton_raphson.py) * [Number Of Digits](https://github.com/TheAlgorithms/Python/blob/master/maths/number_of_digits.py) * [Numerical Integration](https://github.com/TheAlgorithms/Python/blob/master/maths/numerical_integration.py) @@ -546,6 +549,7 @@ * [Sieve Of Eratosthenes](https://github.com/TheAlgorithms/Python/blob/master/maths/sieve_of_eratosthenes.py) * [Sigmoid](https://github.com/TheAlgorithms/Python/blob/master/maths/sigmoid.py) * [Simpson Rule](https://github.com/TheAlgorithms/Python/blob/master/maths/simpson_rule.py) + * [Sock Merchant](https://github.com/TheAlgorithms/Python/blob/master/maths/sock_merchant.py) * [Softmax](https://github.com/TheAlgorithms/Python/blob/master/maths/softmax.py) * [Square Root](https://github.com/TheAlgorithms/Python/blob/master/maths/square_root.py) * [Sum Of Arithmetic Series](https://github.com/TheAlgorithms/Python/blob/master/maths/sum_of_arithmetic_series.py) diff --git a/maths/sock_merchant.py b/maths/sock_merchant.py new file mode 100644 index 000000000..304efec9b --- /dev/null +++ b/maths/sock_merchant.py @@ -0,0 +1,20 @@ +from collections import Counter + + +def sock_merchant(colors: list[int]) -> int: + """ + >>> sock_merchant([10, 20, 20, 10, 10, 30, 50, 10, 20]) + 3 + >>> sock_merchant([1, 1, 3, 3]) + 2 + """ + return sum(socks_by_color // 2 for socks_by_color in Counter(colors).values()) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() + + colors = [int(x) for x in input("Enter socks by color :").rstrip().split()] + print(f"sock_merchant({colors}) = {sock_merchant(colors)}") diff --git a/requirements.txt b/requirements.txt index c28238a07..ef4e18043 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ beautifulsoup4 fake_useragent -keras +keras<2.7.0 lxml matplotlib numpy