This commit is contained in:
Strix 2024-12-01 15:57:47 +01:00
commit d730872d3e
2 changed files with 1037 additions and 0 deletions

1000
Dag 1/input.txt Normal file

File diff suppressed because it is too large Load Diff

37
Dag 1/main.py Normal file
View File

@ -0,0 +1,37 @@
# Initialize the lists to hold the numbers
list1 = []
list2 = []
# Open the file for reading
with open('input.txt', 'r') as file:
for line in file:
# Strip the line of leading/trailing whitespace
stripped_line = line.strip()
# Check if the line contains two numbers separated by three whitespaces
if stripped_line.count(' ') == 1: # Ensure exactly three whitespaces
parts = stripped_line.split(' ')
if len(parts) == 2: # Ensure there are exactly two parts
try:
# Convert parts to numbers and add to respective lists
num1 = int(parts[0])
num2 = int(parts[1])
list1.append(num1)
list2.append(num2)
except ValueError:
# Skip lines where conversion fails
continue
# Output the results
list1.sort()
list2.sort()
zipped = zip(list1,list2)
total_distance = 0
similarity_score = 0
for pair in zipped:
total_distance += abs(pair[0]-pair[1])
similarity_score += pair[0]*list2.count(pair[0])
print(total_distance,similarity_score)