Skip to content

Commit 548972d

Browse files
committed
✨day2 part 1 solved - but not optimised
1 parent 543e2a3 commit 548972d

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
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: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,65 @@
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
56

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

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

24+
def id_wrangle(data: list[str]) -> int:
25+
"""Solution for Day02 AOC25.
26+
Part 1 - looks for ID's that are just repeats.
27+
Part 2 - TBA.
1028
11-
def helperfunction(data: Any) -> None:
12-
return None
29+
Args:
30+
data (list[str]): Input data.
31+
32+
Returns:
33+
int: calculated sum of invalid ids.
34+
"""
35+
invalid_ids: int = 0
36+
37+
for x in data:
38+
lower_id, upper_id = map(int, x.split("-"))
39+
id_range: range = range(lower_id, upper_id+1)
40+
41+
for j in id_range:
42+
id_str = str(j)
43+
# print(list(batched(id_str, 2)))
44+
if len(id_str) % 2 == 0:
45+
split_id_str1, split_id_str2 = list(
46+
batched(id_str, len(id_str)//2)
47+
)
48+
# print(split_id_str1, split_id_str2)
49+
if split_id_str1 == split_id_str2:
50+
# print(id_str, ' = INVALID ID', list(batched(id_str, 2))
51+
invalid_ids += int(id_str)
52+
return invalid_ids
1353

1454

1555
@report_results
16-
def solveday(data: Any) -> AoCResult:
17-
p1: int = 0
56+
def solveday(data: list[str]) -> AoCResult:
57+
p1: int = id_wrangle(data)
1858
p2: int = 0
1959
return p1, p2
2060

2161

22-
expected_test_results: AoCResult = (0, 0)
62+
expected_test_results: AoCResult = (1227775554, 0)
2363

2464

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

0 commit comments

Comments
 (0)