mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
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 3be15ca374
.
* 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 <cclauss@me.com>
This commit is contained in:
parent
85ee27687a
commit
0ea5c734e1
|
@ -39,6 +39,7 @@
|
||||||
* [Binary Xor Operator](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/binary_xor_operator.py)
|
* [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 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)
|
* [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)
|
* [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)
|
* [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)
|
* [Baconian Cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/baconian_cipher.py)
|
||||||
* [Base16](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base16.py)
|
* [Base16](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base16.py)
|
||||||
* [Base32](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base32.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)
|
* [Base85](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base85.py)
|
||||||
* [Beaufort Cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/beaufort_cipher.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)
|
* [Bifid](https://github.com/TheAlgorithms/Python/blob/master/ciphers/bifid.py)
|
||||||
|
@ -219,6 +220,7 @@
|
||||||
* Filters
|
* Filters
|
||||||
* [Bilateral Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/bilateral_filter.py)
|
* [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)
|
* [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)
|
* [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)
|
* [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)
|
* [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)
|
* [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](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)
|
* [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)
|
* [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)
|
* [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)
|
* [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)
|
* [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)
|
* [Sigmoid](https://github.com/TheAlgorithms/Python/blob/master/maths/sigmoid.py)
|
||||||
* [Simpson Rule](https://github.com/TheAlgorithms/Python/blob/master/maths/simpson_rule.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)
|
* [Softmax](https://github.com/TheAlgorithms/Python/blob/master/maths/softmax.py)
|
||||||
* [Square Root](https://github.com/TheAlgorithms/Python/blob/master/maths/square_root.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)
|
* [Sum Of Arithmetic Series](https://github.com/TheAlgorithms/Python/blob/master/maths/sum_of_arithmetic_series.py)
|
||||||
|
|
20
maths/sock_merchant.py
Normal file
20
maths/sock_merchant.py
Normal file
|
@ -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)}")
|
|
@ -1,6 +1,6 @@
|
||||||
beautifulsoup4
|
beautifulsoup4
|
||||||
fake_useragent
|
fake_useragent
|
||||||
keras
|
keras<2.7.0
|
||||||
lxml
|
lxml
|
||||||
matplotlib
|
matplotlib
|
||||||
numpy
|
numpy
|
||||||
|
|
Loading…
Reference in New Issue
Block a user