add: 2022
This commit is contained in:
parent
5ab804addc
commit
df47044ce4
24
2022/day01/alex.py
Normal file
24
2022/day01/alex.py
Normal file
@ -0,0 +1,24 @@
|
||||
f = open("file", "r")
|
||||
Calories = f.read()
|
||||
f.close()
|
||||
|
||||
somme = []
|
||||
sum = 0
|
||||
|
||||
l_calories = Calories.split("\n\n")
|
||||
for i in l_calories:
|
||||
liste = i.split("\n")
|
||||
for j in liste:
|
||||
sum += int(j)
|
||||
somme.append(sum)
|
||||
sum = 0
|
||||
|
||||
def sauver_noel(liste):
|
||||
for i in range(1, len(liste)-1):
|
||||
if liste[i-1] >= liste[i]:
|
||||
maxi = liste[i-1]
|
||||
else:
|
||||
maxi = liste[i]
|
||||
return maxi
|
||||
|
||||
print(sauver_noel(somme))
|
11
2022/day01/part1.py
Normal file
11
2022/day01/part1.py
Normal file
@ -0,0 +1,11 @@
|
||||
f = open("file", "r")
|
||||
str = f.read()
|
||||
f.close()
|
||||
lst = []
|
||||
for paquet in str.split("\n\n"):
|
||||
Sum = 0;
|
||||
for sub_paquet in paquet.split("\n"):
|
||||
if (sub_paquet != ""):
|
||||
Sum += int(sub_paquet)
|
||||
lst.append(Sum);
|
||||
print(max(lst))
|
12
2022/day01/part2.py
Normal file
12
2022/day01/part2.py
Normal file
@ -0,0 +1,12 @@
|
||||
f = open("file", "r")
|
||||
str = f.read()
|
||||
f.close()
|
||||
lst = []
|
||||
for paquet in str.split("\n\n"):
|
||||
Sum = 0;
|
||||
for sub_paquet in paquet.split("\n"):
|
||||
if (sub_paquet != ""):
|
||||
Sum += int(sub_paquet)
|
||||
lst.append(Sum);
|
||||
lst.sort();
|
||||
print(sum(lst[-3:]))
|
2520
2022/day02/main.py
Normal file
2520
2022/day02/main.py
Normal file
File diff suppressed because it is too large
Load Diff
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);
|
19
2022/day04/part1.py
Normal file
19
2022/day04/part1.py
Normal file
@ -0,0 +1,19 @@
|
||||
f = open("file");
|
||||
s = f.read();
|
||||
f.close();
|
||||
menfou = 0;
|
||||
for pair in s.splitlines():
|
||||
elfs = pair.split(",");
|
||||
values = elfs[0].split("-")
|
||||
start1 = int(values[0]);
|
||||
end1 = int(values[1]);
|
||||
values = elfs[1].split("-")
|
||||
start2 = int(values[0]);
|
||||
end2 = int(values[1]);
|
||||
if (start2 <= start1 <= end2 and end1 <= end2):
|
||||
print (start2, start1, end1, end2)
|
||||
menfou += 1;
|
||||
elif (start1 <= start2 <= end1 and end2 <= end1):
|
||||
print (start1, start2, end2, end1)
|
||||
menfou += 1;
|
||||
print(menfou);
|
19
2022/day04/part2.py
Normal file
19
2022/day04/part2.py
Normal file
@ -0,0 +1,19 @@
|
||||
f = open("file");
|
||||
s = f.read();
|
||||
f.close();
|
||||
menfou = 0;
|
||||
for pair in s.splitlines():
|
||||
elfs = pair.split(",");
|
||||
values = elfs[0].split("-")
|
||||
start1 = int(values[0]);
|
||||
end1 = int(values[1]);
|
||||
values = elfs[1].split("-")
|
||||
start2 = int(values[0]);
|
||||
end2 = int(values[1]);
|
||||
verif = 0;
|
||||
for i in range(start1, end1 + 1):
|
||||
for y in range(start2, end2 + 1):
|
||||
if (y == i):
|
||||
verif = 1;
|
||||
menfou += verif;
|
||||
print(menfou);
|
17
2022/day05/part1.py
Normal file
17
2022/day05/part1.py
Normal file
@ -0,0 +1,17 @@
|
||||
f = open("file");
|
||||
s = f.read();
|
||||
f.close();
|
||||
|
||||
splitted = s.split("\n\n");
|
||||
default = splitted[0];
|
||||
instructions = splitted[1];
|
||||
resplitted = default.split("\n")
|
||||
|
||||
for i in range (len(resplitted) - 1):
|
||||
letter = False;
|
||||
for y in range (len(resplitted[i] - 1)):
|
||||
if (resplitted[i][y] == '['):
|
||||
letter = True;
|
||||
elif (letter):
|
||||
letter = False;
|
||||
tab[i ]
|
Loading…
Reference in New Issue
Block a user