AOC/2022/day03/part1.py
2024-08-29 17:12:29 +02:00

15 lines
644 B
Python

f = open("file")
str = f.read();
f.close();
sum = 0;
priority = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
for sac in str.split("\n"):
compartiment1 = sac[:len(sac)//2]
compartiment2 = sac[len(sac)//2:]
for element1 in compartiment1:
if (element1 in compartiment2):
print(element1, priority.index(element1) + 1)
sum += priority.index(element1) + 1;
break;
print (sum);