From 51e96309a83f8a7be716066fc45f3233b92a7c24 Mon Sep 17 00:00:00 2001 From: zb5g22 <zb5g22@soton.ac.uk> Date: Sun, 1 Dec 2024 11:27:00 +0000 Subject: [PATCH] Upload day 1 python file --- Day 1/d1a_+_d1b.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Day 1/d1a_+_d1b.py diff --git a/Day 1/d1a_+_d1b.py b/Day 1/d1a_+_d1b.py new file mode 100644 index 0000000..a956bd2 --- /dev/null +++ b/Day 1/d1a_+_d1b.py @@ -0,0 +1,36 @@ +# -*- 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}") -- GitLab