-
Notifications
You must be signed in to change notification settings - Fork 0
/
11.py
52 lines (49 loc) · 1.32 KB
/
11.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
B=75#25
testing=not False
a = [int(_) for _ in open(0).read().split()]
print(a)
def p2() -> int:
from collections import Counter
b = 0
counter = Counter(a)
while 42:
tmp = Counter()
if testing:print(b)
if b == B:
break
for k, n in counter.items():
#for n in a:
if k == 0:
tmp[1] += n#A.append(1)
elif len(str(k)) % 2 == 0:
N = len(str(k))
tmp[int(str(k)[:N // 2])] += n#A.append(int(str(n)[:N // 2]))
tmp[int(str(k)[N // 2:])] += n#A.append(int(str(n)[N // 2:]))
else:
tmp[k * 2024] += n#A.append(n * 2024)
b+=1
counter = tmp
return sum(counter.values())#len(A)
def p1(a) -> int:
b = 0
while 42:
if testing:print(b)
if b == 25:
break
A = []
for n in a:
if n == 0:
A.append(1)
elif len(str(n)) % 2 == 0:
N = len(str(n))
A.append(int(str(n)[:N // 2]))
A.append(int(str(n)[N // 2:]))
else:
A.append(n * 2024)
b+=1
if testing: print(b, '-', len(A), '-', A)
a = A[:]
return len(A)
res1,res2 = p1(a), p2()
print('part 1:', res1);
print('part 2:', res2);