diff --git a/src/2025/day-02/python/xoyz69/.python-version b/src/2025/day-02/python/xoyz69/.python-version new file mode 100644 index 0000000..24ee5b1 --- /dev/null +++ b/src/2025/day-02/python/xoyz69/.python-version @@ -0,0 +1 @@ +3.13 diff --git a/src/2025/day-02/python/xoyz69/README.md b/src/2025/day-02/python/xoyz69/README.md new file mode 100644 index 0000000..e69de29 diff --git a/src/2025/day-02/python/xoyz69/input b/src/2025/day-02/python/xoyz69/input new file mode 100644 index 0000000..b19b7c4 --- /dev/null +++ b/src/2025/day-02/python/xoyz69/input @@ -0,0 +1 @@ +749639-858415,65630137-65704528,10662-29791,1-17,9897536-10087630,1239-2285,1380136-1595466,8238934-8372812,211440-256482,623-1205,102561-122442,91871983-91968838,62364163-62554867,3737324037-3737408513,9494926669-9494965937,9939271919-9939349036,83764103-83929201,24784655-24849904,166-605,991665-1015125,262373-399735,557161-618450,937905586-937994967,71647091-71771804,8882706-9059390,2546-10476,4955694516-4955781763,47437-99032,645402-707561,27-86,97-157,894084-989884,421072-462151 diff --git a/src/2025/day-02/python/xoyz69/main.py b/src/2025/day-02/python/xoyz69/main.py new file mode 100644 index 0000000..7ae5585 --- /dev/null +++ b/src/2025/day-02/python/xoyz69/main.py @@ -0,0 +1,78 @@ +def part01(): + print("Advent of Code 2025 Day 2 part 1") + + with open("input", "r") as file_input: + line = file_input.readlines()[0].replace("\n", "") # It is all in one line + + ranges = line.split(",") + + sum = 0 + + for r in ranges: + splitted = r.split("-") + start, end = int(splitted[0]), int(splitted[1]) + for i in range(start, end + 1): + textnr = str(i) + if len(textnr) % 2 != 0: + continue + + half = int(len(textnr) / 2) + part1 = textnr[:half] + part2 = textnr[half:] + + if part1 == part2: + sum += i + + print(" -> Result:", sum) + + +def part02(): + print("Advent of Code 2025 Day 2 part 2") + + with open("input", "r") as file_input: + line = file_input.readlines()[0].replace("\n", "") # It is all in one line + + ranges = line.split(",") + + sum = 0 + + for r in ranges: + splitted = r.split("-") + start, end = int(splitted[0]), int(splitted[1]) + print("----------------") + print(start, end) + for i in range(start, end + 1): + textnr = str(i) + + section_size = round(len(textnr) / 2) + invalid = False + + while section_size > 0 and not invalid: + # print(start, end, i, section_size) + if len(textnr) % section_size == 0: + parts = [] + works = True + for p in range(0, len(textnr), section_size): + parts.append(textnr[p : p + section_size]) + + for a in parts: + if a != parts[-1]: + works = False + + if works: + invalid = True + + section_size -= 1 + + # print("\t", invalid) + + if invalid: + print(f"\tFound invalid id: {i:,}") + sum += i + + print(f" -> Result: {sum:,}") + + +if __name__ == "__main__": + part01() + part02() diff --git a/src/2025/day-02/python/xoyz69/pyproject.toml b/src/2025/day-02/python/xoyz69/pyproject.toml new file mode 100644 index 0000000..e57bfb2 --- /dev/null +++ b/src/2025/day-02/python/xoyz69/pyproject.toml @@ -0,0 +1,7 @@ +[project] +name = "xoyz69" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.13" +dependencies = [] diff --git a/src/2025/day-02/python/xoyz69/uv.lock b/src/2025/day-02/python/xoyz69/uv.lock new file mode 100644 index 0000000..44dfef4 --- /dev/null +++ b/src/2025/day-02/python/xoyz69/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 3 +requires-python = ">=3.13" + +[[package]] +name = "xoyz69" +version = "0.1.0" +source = { virtual = "." }