You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
694 B
24 lines
694 B
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
|
|
if __name__ == '__main__':
|
|
tuples = [[int(l) for l in line.strip('\n').split(' ')] for line in open(sys.argv[1])]
|
|
first, second = [sorted(a) for a in zip(*tuples)]
|
|
# first = []
|
|
# second = []
|
|
# for line in lines:
|
|
# f, s = line.split(' ')
|
|
# first.append(int(f))
|
|
# second.append(int(s))
|
|
# first.sort()
|
|
# second.sort()
|
|
|
|
# challenge 1
|
|
res1 = sum([abs(x-y) for (x,y) in zip(first, second)])
|
|
print(f"challenge 1:\n{res1}\n")
|
|
|
|
# challenge 2
|
|
res2 = sum([x * second.count(x) for x in first])
|
|
print(f"challenge 2:\n{res2}")
|
|
|
|
|