Advent of Code 2022 https://adventofcode.com/2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

day6-1.py 847B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -------
  2. # imports
  3. # -------
  4. from string import ascii_letters
  5. # ---------
  6. # constants
  7. # ---------
  8. DEBUG=True
  9. HEADER_LEN = 4
  10. # ----------------
  11. # helper functions
  12. # ----------------
  13. def debug(*args):
  14. if DEBUG:
  15. print(args)
  16. # -------------
  17. # main function
  18. # -------------
  19. def main():
  20. with open("input6.txt", "r") as file:
  21. intext = file.read()
  22. inlen = len(intext)
  23. for i in range(inlen):
  24. lets = []
  25. for j in range(HEADER_LEN):
  26. clet = intext[i+j]
  27. lets.append(clet)
  28. if len(set(lets)) != HEADER_LEN:
  29. print(f"Non-unique: {''.join(lets)} in {i+1}-{i+HEADER_LEN}")
  30. else:
  31. print(f"Unique! {''.join(lets)} in {i+1}-{i+HEADER_LEN}")
  32. break
  33. # --------------
  34. # run the script
  35. # --------------
  36. if __name__ == "__main__":
  37. main()