Logo
Explore Help
Register Sign In
TheAlgorithms/Python
1
0
Fork 0
You've already forked Python
Code Issues Pull Requests Actions 2 Packages Projects Releases Wiki Activity
Files
master
Python/maths/sock_merchant.py

21 lines
502 B
Python
Raw Permalink Normal View History

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 <cclauss@me.com>
2021-11-04 01:54:50 +05:30
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)}")
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.24.6 Page: 164ms Template: 2ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API