# Advent of Code 2025 https://adventofcode.com/2025 Why do I make these separate repos every year?
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # encoding: utf-8
  2. # Given a list of comma-separated pairs of numbers separated by a dash
  3. # e.g. 111-999,22-33
  4. # find all the numbers that are some sequence of digits repeated
  5. # any number of times
  6. import logging
  7. import random
  8. import re
  9. logger = logging.Logger(__name__)
  10. logger.addHandler(logging.StreamHandler())
  11. logger.setLevel(logging.INFO)
  12. TESTING = False
  13. INPUT_FILE = "day2_test_input.txt" if TESTING else "day2_input.txt"
  14. def main():
  15. with open(INPUT_FILE, "r") as f:
  16. input_line = f.readline().strip()
  17. inranges = [x.strip() for x in input_line.split(",")]
  18. num_ranges = len(inranges)
  19. tenths = num_ranges//10
  20. logger.debug(f"Received {num_ranges} ranges.")
  21. all_invalids = []
  22. for i, r in enumerate(inranges):
  23. if tenths and i % tenths == 0:
  24. logger.debug(f"Processing range {i}.")
  25. x, y = [int(q) for q in r.strip().split("-")]
  26. logger.debug(f"x: {x}, y: {y}")
  27. invalids = []
  28. k = x
  29. while k <= y:
  30. found = False
  31. s_k = str(k)
  32. l = len(s_k)
  33. m = l//2
  34. t = 1
  35. while not found and t <= m:
  36. pattern = fr'^({s_k[:t]}){{2,}}$'
  37. found = re.match(pattern, s_k) is not None
  38. # if random.randint(1,10) == 1:
  39. logger.debug(f"Pattern: {pattern}, value: {s_k}, found: {found}")
  40. if found:
  41. logger.debug(f"Found a multiple: {k}")
  42. invalids.append(k)
  43. t += 1
  44. k += 1
  45. all_invalids.extend(invalids)
  46. logger.info(f"Found {len(all_invalids)} invalid IDs.")
  47. logger.info(f"Sum of invalid IDs is {sum(all_invalids)}.")
  48. if __name__ == "__main__":
  49. main()