-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpart2.py
More file actions
24 lines (18 loc) · 686 Bytes
/
Copy pathpart2.py
File metadata and controls
24 lines (18 loc) · 686 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Question 2 Code
# Read the input file
with open("e:/Advent of Code/Day-01/input.txt") as f:
lines = f.read().strip().split("\n")
# Parse the input into two separate lists
left = []
right = []
for line in lines:
l, r = map(int, line.split()) # Split each line into two numbers
left.append(l) # Add to left list
right.append(r) # Add to right list
# Calculate the similarity score
similarity_score = 0
for num in left:
count_in_right = right.count(num) # Count occurrences in the right list
similarity_score += num * count_in_right # Increment similarity score
# Print the result
print("Similarity Score:", similarity_score)