add: 2022
This commit is contained in:
14
2022/day03/part1.py
Normal file
14
2022/day03/part1.py
Normal file
@ -0,0 +1,14 @@
|
||||
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);
|
22
2022/day03/part2.py
Normal file
22
2022/day03/part2.py
Normal file
@ -0,0 +1,22 @@
|
||||
f = open("file");
|
||||
str = f.read();
|
||||
f.close();
|
||||
|
||||
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']
|
||||
|
||||
|
||||
splitted = []
|
||||
str = str.split("\n")
|
||||
while len(str) != 0:
|
||||
splitted.append("\n".join(str[:3]));
|
||||
str = str[3:];
|
||||
|
||||
sum = 0;
|
||||
for group in splitted:
|
||||
resplitted = group.split("\n");
|
||||
print(resplitted)
|
||||
for i in resplitted[0]:
|
||||
if (i in resplitted[1] and i in resplitted[2]):
|
||||
sum += priority.index(i) + 1;
|
||||
break;
|
||||
print (sum);
|
Reference in New Issue
Block a user