blob: b95c0c3c164c06931efe5e4d575c5d02afe5d39c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#!/usr/bin/env python3
import sys
def element_digit_sum(ints: list) -> int:
"""Calculate the absolute difference between the element sum and the sum
of each digit
Args:
ints (list): List of integers
Returns:
int: The absolute difference
"""
element_sum = sum(ints)
digit_sum = sum(int(i) for s in map(str, ints) for i in s)
return abs(element_sum - digit_sum)
def main():
# Convert input into integers
array = [int(n) for n in sys.argv[1:]]
result = element_digit_sum(array)
print(result)
if __name__ == '__main__':
main()
|