Skip to content

Commit 32e066f

Browse files
authored
Merge pull request #2 from bloopy-code/newday/day02
Newday/day02
2 parents c297668 + 4eb2feb commit 32e066f

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

aoc_25/inputs/day02.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
PLACEHOLDER INPUT
1+
975119-1004307,35171358-35313940,6258659887-6258804661,737649-837633,85745820-85956280,9627354-9679470,2327309144-2327509647,301168-351545,537261-631588,364281214-364453549,9563727253-9563879587,3680-9127,388369417-388406569,6677501-6752949,650804-678722,3314531-3365076,1052-2547,24134-68316,8888820274-8888998305,82614-107458,456819-529037,358216-389777,24222539-24266446,874565-916752,3886244-3960191,25-110,9696951376-9696996784,171-671,5656545867-5656605587,75795017-75865731,1-16,181025-232078

aoc_25/solutions/day02.py

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,89 @@
1-
"""Day 2 - Title Goes Here"""
1+
"""Day 2 - Gift Shop"""
22

33
from typing import Any
4-
from utils.aoc_utils import input_for_day, report_results, AoCResult
4+
from utils.aoc_utils import report_results, AoCResult, input_for_day
5+
from itertools import batched
6+
from rich.progress import track
57

8+
EXAMPLE: list[str] = [
9+
"11-22",
10+
"95-115",
11+
"998-1012",
12+
"1188511880-1188511890",
13+
"222220-222224",
14+
"1698522-1698528",
15+
"446443-446449",
16+
"38593856-38593862",
17+
"565653-565659",
18+
"824824821-824824827",
19+
"2121212118-2121212124",
20+
]
21+
INPUT_DATA: str = input_for_day(2, 2025)
22+
DATA: list[str] = INPUT_DATA.split(",")
623

7-
EXAMPLE: list = []
8-
DATA = input_for_day(2)
924

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!
1029
11-
def helperfunction(data: Any) -> None:
12-
return None
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:
49+
"""Solution for Day02 AOC25.
50+
Part 1 - looks for ID's that are just repeats.
51+
Part 2 - TBA.
52+
53+
Args:
54+
data (list[str]): Input data.
55+
56+
Returns:
57+
AoCResult: part1 invalid ids, part 2 invalid ids
58+
"""
59+
invalid_ids_p1: int = 0
60+
invalid_ids_p2: int = 0
61+
62+
for x in track(data):
63+
lower_id, upper_id = map(int, x.split("-"))
64+
id_range: range = range(lower_id, upper_id + 1)
65+
66+
for j in id_range:
67+
id_str: str = str(j)
68+
invalid_ids_p2 += part2_wrangle(id_str)
69+
# print(list(batched(id_str, 2)))
70+
if len(id_str) % 2 == 0:
71+
split_id_str1, split_id_str2 = list(batched(id_str, len(id_str) // 2))
72+
# print(split_id_str1, split_id_str2)
73+
if split_id_str1 == split_id_str2:
74+
# print(id_str, ' = INVALID ID', list(batched(id_str, 2))
75+
invalid_ids_p1 += int(id_str)
76+
77+
return invalid_ids_p1, invalid_ids_p2
1378

1479

1580
@report_results
16-
def solveday(data: Any) -> AoCResult:
17-
p1: int = 0
18-
p2: int = 0
81+
def solveday(data: list[str]) -> AoCResult:
82+
p1, p2 = id_wrangle(data)
1983
return p1, p2
2084

2185

22-
expected_test_results: AoCResult = (0, 0)
86+
expected_test_results: AoCResult = (1227775554, 4174379265)
2387

2488

2589
def tests(test_input: Any) -> None:

0 commit comments

Comments
 (0)