Skip to content
Snippets Groups Projects
Commit 51e96309 authored by zb5g22's avatar zb5g22
Browse files

Upload day 1 python file

parent a4ee11ad
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 1 10:43:07 2024
@author: zoë
"""
import numpy as np
list_one = []
list_two = []
with open("input", "r") as file:
data = file.readlines()
file.close()
for row in data:
washed = row.strip("\n").split(" ")
list_one.append(int(washed[0]))
list_two.append(int(washed[-1]))
list_one.sort()
list_two.sort()
similarity = 0
for number in list_one:
indices = [i for i, item in enumerate(list_two) if item == number]
similarity += number * len(indices)
list_one = np.array(list_one)
list_two = np.array(list_two)
list_difference = np.abs(list_one - list_two)
print(f"Total distance is: {np.sum(list_difference)}")
print(f"Similarity score is: {similarity}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment