From bf06795b6bc66a23c71ebf5ae0f2e2297819aa05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20T=C3=B3th?= Date: Tue, 2 Dec 2025 09:33:38 +0100 Subject: [PATCH] Day 2: Part 1 --- day2/index.html | 139 ++++++++++++++++++++++++++++++++++++++++++++++++ day2/input.txt | 1 + day2/main.py | 20 +++++++ 3 files changed, 160 insertions(+) create mode 100644 day2/index.html create mode 100644 day2/input.txt create mode 100644 day2/main.py diff --git a/day2/index.html b/day2/index.html new file mode 100644 index 0000000..af56aea --- /dev/null +++ b/day2/index.html @@ -0,0 +1,139 @@ + + + + +Day 2 - Advent of Code 2025 + + + + + + +

Advent of Code

   int y=2025;

+ + + +
+

--- Day 2: Gift Shop ---

You get inside and take the elevator to its only other stop: the gift shop. "Thank you for visiting the North Pole!" gleefully exclaims a nearby sign. You aren't sure who is even allowed to visit the North Pole, but you know you can access the lobby through here, and from there you can access the rest of the North Pole base.

+

As you make your way through the surprisingly extensive selection, one of the clerks recognizes you and asks for your help.

+

As it turns out, one of the younger Elves was playing on a gift shop computer and managed to add a whole bunch of invalid product IDs to their gift shop database! Surely, it would be no trouble for you to identify the invalid product IDs for them, right?

+

They've even checked most of the product ID ranges already; they only have a few product ID ranges (your puzzle input) that you'll need to check. For example:

+
11-22,95-115,998-1012,1188511880-1188511890,222220-222224,
+1698522-1698528,446443-446449,38593856-38593862,565653-565659,
+824824821-824824827,2121212118-2121212124
+

(The ID ranges are wrapped here for legibility; in your input, they appear on a single long line.)

+

The ranges are separated by commas (,); each range gives its first ID and last ID separated by a dash (-).

+

Since the young Elf was just doing silly patterns, you can find the invalid IDs by looking for any ID which is made only of some sequence of digits repeated twice. So, 55 (5 twice), 6464 (64 twice), and 123123 (123 twice) would all be invalid IDs.

+

None of the numbers have leading zeroes; 0101 isn't an ID at all. (101 is a valid ID that you would ignore.)

+

Your job is to find all of the invalid IDs that appear in the given ranges. In the above example:

+
    +
  • 11-22 has two invalid IDs, 11 and 22.
  • +
  • 95-115 has one invalid ID, 99.
  • +
  • 998-1012 has one invalid ID, 1010.
  • +
  • 1188511880-1188511890 has one invalid ID, 1188511885.
  • +
  • 222220-222224 has one invalid ID, 222222.
  • +
  • 1698522-1698528 contains no invalid IDs.
  • +
  • 446443-446449 has one invalid ID, 446446.
  • +
  • 38593856-38593862 has one invalid ID, 38593859.
  • +
  • The rest of the ranges contain no invalid IDs.
  • +
+

Adding up all the invalid IDs in this example produces 1227775554.

+

What do you get if you add up all of the invalid IDs?

+
+

To play, please identify yourself via one of these services:

+

[GitHub] [Google] [Twitter] [Reddit] - [How Does Auth Work?]

+
+ + + + + + \ No newline at end of file diff --git a/day2/input.txt b/day2/input.txt new file mode 100644 index 0000000..cc522c9 --- /dev/null +++ b/day2/input.txt @@ -0,0 +1 @@ +385350926-385403705,48047-60838,6328350434-6328506208,638913-698668,850292-870981,656-1074,742552-796850,4457-6851,138-206,4644076-4851885,3298025-3353031,8594410816-8594543341,396-498,1558-2274,888446-916096,12101205-12154422,2323146444-2323289192,37-57,101-137,46550018-46679958,79-96,317592-341913,495310-629360,33246-46690,14711-22848,1-17,2850-4167,3723700171-3723785996,190169-242137,272559-298768,275-365,7697-11193,61-78,75373-110112,425397-451337,9796507-9899607,991845-1013464,77531934-77616074 diff --git a/day2/main.py b/day2/main.py new file mode 100644 index 0000000..1b0bf39 --- /dev/null +++ b/day2/main.py @@ -0,0 +1,20 @@ +def is_invalid_id(n: int) -> bool: + s = str(n) + if len(s) % 2 != 0: + return False + half = len(s) // 2 + return s[:half] == s[half:] + + +total = 0 + +with open("input.txt") as f: + line = f.read().strip() + +for part in line.split(","): + lo, hi = map(int, part.split("-")) + for n in range(lo, hi + 1): + if is_invalid_id(n): + total += n + +print(total)