@@ -21,6 +21,33 @@ def solve(part: int, data: str) -> int:
2121 total += counts [i ]
2222 return total
2323
24+ l = len (data )
25+ window = collections .deque ()
26+ mentors = collections .defaultdict (int )
27+ for i in range (1000 ):
28+ j = data [i % l ]
29+ window .append (j )
30+ if j .isupper ():
31+ mentors [j .lower ()] += 1
32+
33+ limit = 1000 * (l - 1 )
34+ for idx , n in enumerate (j for i in range (1000 ) for j in data ):
35+ if idx > 1000 :
36+ j = window .popleft ()
37+ if j .isupper ():
38+ mentors [j .lower ()] -= 1
39+ j = data [(idx + 1000 ) % l ] if idx < limit else " "
40+ window .append (j )
41+ if j .isupper ():
42+ mentors [j .lower ()] += 1
43+ if n .islower ():
44+ total += mentors [n ]
45+
46+ return total
47+
48+
49+
50+
2451 once = math .ceil (1000 / len (data ))
2552 twice = once * 2
2653 three = once * 3
@@ -29,21 +56,18 @@ def solve(part: int, data: str) -> int:
2956 for idx , m in enumerate (j for i in range (twice ) for j in data ):
3057 if m .isupper ():
3158 mentors [m .lower ()].add (idx )
32- print ("Done counting mentors" )
3359
3460 edges = 0
3561 for idx , m in enumerate (j for i in range (twice ) for j in data ):
3662 if m .islower ():
3763 for i in mentors [m .lower ()]:
3864 if abs (idx - i ) <= 1000 :
3965 edges += 1
40- print ("edges" , edges )
4166
4267 mentors = collections .defaultdict (set )
4368 for idx , m in enumerate (j for i in range (three ) for j in data ):
4469 if m .isupper ():
4570 mentors [m .lower ()].add (idx )
46- print ("Done counting mentors" )
4771
4872 middle = 0
4973 count = 1000 - twice
@@ -52,7 +76,6 @@ def solve(part: int, data: str) -> int:
5276 for i in mentors [m .lower ()]:
5377 if abs (idx + once * len (data ) - i ) <= 1000 :
5478 middle += 1
55- print (f"{ len (data )= } , { edges = } , { middle = } , { once = } , { twice = } , { three = } , { count = } , { count + twice = } " )
5679
5780 return edges + middle * count
5881
0 commit comments