Skip to content

Commit 0ea5c73

Browse files
SouvikGhosh05github-actionscclauss
authored
sock_merchant.py: Matching socks by color (TheAlgorithms#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 3be15ca. * 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 <[email protected]>
1 parent 85ee276 commit 0ea5c73

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

DIRECTORY.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* [Binary Xor Operator](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/binary_xor_operator.py)
4040
* [Count 1S Brian Kernighan Method](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/count_1s_brian_kernighan_method.py)
4141
* [Count Number Of One Bits](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/count_number_of_one_bits.py)
42+
* [Gray Code Sequence](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/gray_code_sequence.py)
4243
* [Reverse Bits](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/reverse_bits.py)
4344
* [Single Bit Manipulation Operations](https://github.com/TheAlgorithms/Python/blob/master/bit_manipulation/single_bit_manipulation_operations.py)
4445

@@ -63,7 +64,7 @@
6364
* [Baconian Cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/baconian_cipher.py)
6465
* [Base16](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base16.py)
6566
* [Base32](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base32.py)
66-
* [Base64 Encoding](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base64_encoding.py)
67+
* [Base64](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base64.py)
6768
* [Base85](https://github.com/TheAlgorithms/Python/blob/master/ciphers/base85.py)
6869
* [Beaufort Cipher](https://github.com/TheAlgorithms/Python/blob/master/ciphers/beaufort_cipher.py)
6970
* [Bifid](https://github.com/TheAlgorithms/Python/blob/master/ciphers/bifid.py)
@@ -219,6 +220,7 @@
219220
* Filters
220221
* [Bilateral Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/bilateral_filter.py)
221222
* [Convolve](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/convolve.py)
223+
* [Gabor Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/gabor_filter.py)
222224
* [Gaussian Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/gaussian_filter.py)
223225
* [Median Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/median_filter.py)
224226
* [Sobel Filter](https://github.com/TheAlgorithms/Python/blob/master/digital_image_processing/filters/sobel_filter.py)
@@ -511,6 +513,7 @@
511513
* [Modular Exponential](https://github.com/TheAlgorithms/Python/blob/master/maths/modular_exponential.py)
512514
* [Monte Carlo](https://github.com/TheAlgorithms/Python/blob/master/maths/monte_carlo.py)
513515
* [Monte Carlo Dice](https://github.com/TheAlgorithms/Python/blob/master/maths/monte_carlo_dice.py)
516+
* [Nevilles Method](https://github.com/TheAlgorithms/Python/blob/master/maths/nevilles_method.py)
514517
* [Newton Raphson](https://github.com/TheAlgorithms/Python/blob/master/maths/newton_raphson.py)
515518
* [Number Of Digits](https://github.com/TheAlgorithms/Python/blob/master/maths/number_of_digits.py)
516519
* [Numerical Integration](https://github.com/TheAlgorithms/Python/blob/master/maths/numerical_integration.py)
@@ -546,6 +549,7 @@
546549
* [Sieve Of Eratosthenes](https://github.com/TheAlgorithms/Python/blob/master/maths/sieve_of_eratosthenes.py)
547550
* [Sigmoid](https://github.com/TheAlgorithms/Python/blob/master/maths/sigmoid.py)
548551
* [Simpson Rule](https://github.com/TheAlgorithms/Python/blob/master/maths/simpson_rule.py)
552+
* [Sock Merchant](https://github.com/TheAlgorithms/Python/blob/master/maths/sock_merchant.py)
549553
* [Softmax](https://github.com/TheAlgorithms/Python/blob/master/maths/softmax.py)
550554
* [Square Root](https://github.com/TheAlgorithms/Python/blob/master/maths/square_root.py)
551555
* [Sum Of Arithmetic Series](https://github.com/TheAlgorithms/Python/blob/master/maths/sum_of_arithmetic_series.py)

maths/sock_merchant.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from collections import Counter
2+
3+
4+
def sock_merchant(colors: list[int]) -> int:
5+
"""
6+
>>> sock_merchant([10, 20, 20, 10, 10, 30, 50, 10, 20])
7+
3
8+
>>> sock_merchant([1, 1, 3, 3])
9+
2
10+
"""
11+
return sum(socks_by_color // 2 for socks_by_color in Counter(colors).values())
12+
13+
14+
if __name__ == "__main__":
15+
import doctest
16+
17+
doctest.testmod()
18+
19+
colors = [int(x) for x in input("Enter socks by color :").rstrip().split()]
20+
print(f"sock_merchant({colors}) = {sock_merchant(colors)}")

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
beautifulsoup4
22
fake_useragent
3-
keras
3+
keras<2.7.0
44
lxml
55
matplotlib
66
numpy

0 commit comments

Comments
 (0)