-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeAdvent_10.py
63 lines (40 loc) · 1.24 KB
/
codeAdvent_10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'''
Created on 31 july 2021
@author: Antonio Martínez Fernández
'''
array=[]
contador=0
diff_1=0
diff_3=1 # el ultimo siempre será diferencia de 3
def lectura():
archivo = open("input9.txt")
while True:
linea = archivo.readline()
if not linea:
break
array.append(int(linea))
array.sort()
def getChained_Addapters():
global diff_1
global diff_3
anterior=0
for i in array:
if(i-anterior==3):
diff_3+=1
elif(i-anterior==1):
diff_1+=1
anterior=i
return diff_1*diff_3
def allChained_Combinations():
dp = [1]
for i in range(1, len(array)): # recorre desde el 1
ans = 0
for j in range(i): # recorre los anteriores a i
if array[j] + 3 >= array[i]: # comprueba si no es imprescindible
ans += dp[j]
dp.append(ans) # para cada numero escribe el total acumulado de posibilidades
print("part 2", dp[len(array)-1])
if __name__ == '__main__':
lectura()
print("part 1 ",getChained_Addapters())
allChained_Combinations()