33from typing import Any
44from utils .aoc_utils import report_results , AoCResult , input_for_day
55from itertools import batched
6+ from rich .progress import track
67
78EXAMPLE : list [str ] = [
89 "11-22" ,
1516 "38593856-38593862" ,
1617 "565653-565659" ,
1718 "824824821-824824827" ,
18- "2121212118-2121212124"
19+ "2121212118-2121212124" ,
1920]
2021INPUT_DATA : str = input_for_day (2 , 2025 )
2122DATA : list [str ] = INPUT_DATA .split ("," )
2223
2324
24- def id_wrangle (data : list [str ]) -> int :
25+ def part2_wrangle (id_str : str ) -> int :
26+ """Part 2 wrangle.
27+ Find chunks of string id to make it even chunks.
28+ If a len(set) of those chunks == 1 - invalid id!
29+
30+ Args:
31+ id_str (str): ID String
32+
33+ Returns:
34+ int: either the invalid id int or 0
35+ """
36+ # find each divisor
37+ id_len : int = len (id_str )
38+ divisors : list [int ] = [x for x in range (1 , id_len ) if id_len % x == 0 ]
39+
40+ for d in divisors :
41+ if id_len / d >= 2 :
42+ b : list [tuple [str , ...]] = list (batched (id_str , d ))
43+ if len (set (b )) == 1 :
44+ return int (id_str )
45+ return 0
46+
47+
48+ def id_wrangle (data : list [str ]) -> AoCResult :
2549 """Solution for Day02 AOC25.
2650 Part 1 - looks for ID's that are just repeats.
2751 Part 2 - TBA.
@@ -30,36 +54,36 @@ def id_wrangle(data: list[str]) -> int:
3054 data (list[str]): Input data.
3155
3256 Returns:
33- int: calculated sum of invalid ids.
57+ AoCResult: part1 invalid ids, part 2 invalid ids
3458 """
35- invalid_ids : int = 0
59+ invalid_ids_p1 : int = 0
60+ invalid_ids_p2 : int = 0
3661
37- for x in data :
62+ for x in track ( data ) :
3863 lower_id , upper_id = map (int , x .split ("-" ))
39- id_range : range = range (lower_id , upper_id + 1 )
64+ id_range : range = range (lower_id , upper_id + 1 )
4065
4166 for j in id_range :
42- id_str = str (j )
67+ id_str : str = str (j )
68+ invalid_ids_p2 += part2_wrangle (id_str )
4369 # print(list(batched(id_str, 2)))
4470 if len (id_str ) % 2 == 0 :
45- split_id_str1 , split_id_str2 = list (
46- batched (id_str , len (id_str )// 2 )
47- )
71+ split_id_str1 , split_id_str2 = list (batched (id_str , len (id_str ) // 2 ))
4872 # print(split_id_str1, split_id_str2)
4973 if split_id_str1 == split_id_str2 :
5074 # print(id_str, ' = INVALID ID', list(batched(id_str, 2))
51- invalid_ids += int (id_str )
52- return invalid_ids
75+ invalid_ids_p1 += int (id_str )
76+
77+ return invalid_ids_p1 , invalid_ids_p2
5378
5479
5580@report_results
5681def solveday (data : list [str ]) -> AoCResult :
57- p1 : int = id_wrangle (data )
58- p2 : int = 0
82+ p1 , p2 = id_wrangle (data )
5983 return p1 , p2
6084
6185
62- expected_test_results : AoCResult = (1227775554 , 0 )
86+ expected_test_results : AoCResult = (1227775554 , 4174379265 )
6387
6488
6589def tests (test_input : Any ) -> None :
0 commit comments