From 431c30464525ecc57c90bdcf70881edb5615b625 Mon Sep 17 00:00:00 2001 From: shockrah Date: Tue, 3 Dec 2024 01:16:52 -0800 Subject: [PATCH] excellent --- 1/1.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/1/1.py b/1/1.py index 2474bd1..e25f050 100644 --- a/1/1.py +++ b/1/1.py @@ -1,13 +1,5 @@ -def distances(left: list[int], right: list[int]) -> list[int]: - left, right = sorted(left), sorted(right) - return [abs(l-r) for l, r in zip(left, right)] - -if __name__ == '__main__': - with open('1.input') as file: - left, right = [], [] - for line in file: - l, r = line.split() - l, r = int(l), int(r) - left.append(l) - right.append(r) - print(sum(distances(left, right))) \ No newline at end of file +with open('1.input') as f: + l,r=[],[] + d=lambda a,b:[abs(a-b) for a,b in zip(sorted(a), sorted(b))] + for i in f:l.append(int(i.split()[0])),r.append(int(i.split()[1])) + print(sum(d(l,r))) \ No newline at end of file