diff options
| author | FanDabbyDoozy <ps20163152@student.vsa.edu.hk> | 2024-12-01 22:08:15 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-01 22:08:15 +0800 |
| commit | 748d3df3e4be8c4d53e3032631e16f6ec9a7ddfe (patch) | |
| tree | 2f825829985553c73345021279c5648396314418 /2024 | |
| parent | af9b4431f36a28a0b52bc2a313e1d8ba98bc47d8 (diff) | |
Create 1A.py
Diffstat (limited to '2024')
| -rw-r--r-- | 2024/1A.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/2024/1A.py b/2024/1A.py new file mode 100644 index 0000000..72f4cee --- /dev/null +++ b/2024/1A.py @@ -0,0 +1,26 @@ +loc1 = [] +loc2 = [] + +with open('1A.txt', 'r') as file: + for line in file: + parts = line.strip().split(" ") + if len(parts) == 2: + val1 = int(parts[0]) + val2 = int(parts[1]) + + loc1.append(val1) + loc2.append(val2) + +print(sorted(loc1)) +print(sorted(loc2)) +sorted_loc1 = sorted(loc1) +sorted_loc2 = sorted(loc2) + +final_distance = 0 + +for i in range(len(loc1)): + distance = sorted_loc2[i] - sorted_loc1[i] + abs_distance = abs(distance) + final_distance += abs_distance + +print(final_distance) |
