Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from typing import Union
- def naive_dash_sum_dict(digits):
- """
- Calculates the sum of dashes in numbers.
- """
- dashes = {
- '0': 6, '1': 2, '2': 5, '3': 5,
- '4': 4, '5': 5, '6': 6, '7': 3,
- '8': 7, '9': 6,
- }
- result = 0
- for digit in digits:
- result += dashes[digit]
- return result
- def dash_sum1(digits):
- """
- Calculates the sum of dashes in numbers.
- The digits must be a string.
- """
- dashes = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
- result = 0
- for digit in digits:
- result += dashes[int(digit)]
- return result
- def dash_sum2(digits):
- """
- Calculates the sum of dashes in numbers.
- The digits can be an integer or a string.
- """
- dashes = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
- result = 0
- digits = str(digits)
- for digit in digits:
- result += dashes[int(digit)]
- return result
- def dash_sum3(digits: Union[str, int]):
- """
- Calculates the sum of dashes in numbers.
- The digits can be an integer or a string.
- """
- dashes = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
- result = 0
- digits = str(digits)
- for digit in map(int, digits):
- result += dashes[digit]
- return result
- def dash_sum4(digits: Union[str, int]):
- """
- Calculates the sum of dashes in numbers.
- The digits can be an integer or a string.
- """
- dashes = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
- result = 0
- for digit in map(int, str(digits)):
- result += dashes[digit]
- return result
- def dash_sum5(digits: Union[str, int]):
- """
- Calculates the sum of dashes in numbers.
- The digits can be an integer or a string.
- """
- dashes = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
- return sum(
- dashes[digit]
- for digit in
- map(int, str(digits))
- )
- functions = [globals()[func] for func in sorted(dir()) if 'dash' in func]
- test_str = '1234567890'
- print('Test string:', test_str)
- for func in functions:
- print(f'{func.__name__}: {func(test_str)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement