| # --------- | # --------- | ||||
| DEBUG=True | DEBUG=True | ||||
| HEADER_LEN = 4 | |||||
| # ---------------- | # ---------------- | ||||
| # helper functions | # helper functions | ||||
| for i in range(inlen): | for i in range(inlen): | ||||
| lets = [] | lets = [] | ||||
| for j in range(4): | |||||
| for j in range(HEADER_LEN): | |||||
| clet = intext[i+j] | clet = intext[i+j] | ||||
| lets.append(clet) | lets.append(clet) | ||||
| if len(set(lets)) != 4: | |||||
| print(f"Non-unique: {''.join(lets)} in {i+1}-{i+4}") | |||||
| if len(set(lets)) != HEADER_LEN: | |||||
| print(f"Non-unique: {''.join(lets)} in {i+1}-{i+HEADER_LEN}") | |||||
| else: | else: | ||||
| print(f"Unique! {''.join(lets)} in {i+1}-{i+4}") | |||||
| print(f"Unique! {''.join(lets)} in {i+1}-{i+HEADER_LEN}") | |||||
| break | break | ||||
| # -------------- | # -------------- |
| # --------- | # --------- | ||||
| DEBUG=True | DEBUG=True | ||||
| HEADER_LEN = 14 | |||||
| # ---------------- | # ---------------- | ||||
| # helper functions | # helper functions | ||||
| for i in range(inlen): | for i in range(inlen): | ||||
| lets = [] | lets = [] | ||||
| for j in range(14): | |||||
| for j in range(HEADER_LEN): | |||||
| clet = intext[i+j] | clet = intext[i+j] | ||||
| lets.append(clet) | lets.append(clet) | ||||
| if len(set(lets)) != 14: | |||||
| print(f"Non-unique: {''.join(lets)} in {i+1}-{i+14}") | |||||
| if len(set(lets)) != HEADER_LEN: | |||||
| print(f"Non-unique: {''.join(lets)} in {i+1}-{i+HEADER_LEN}") | |||||
| else: | else: | ||||
| print(f"Unique! {''.join(lets)} in {i+1}-{i+14}") | |||||
| print(f"Unique! {''.join(lets)} in {i+1}-{i+HEADER_LEN}") | |||||
| break | break | ||||
| # -------------- | # -------------- |
| # ------- | |||||
| # imports | |||||
| # ------- | |||||
| from string import ascii_letters | |||||
| # --------- | |||||
| # constants | |||||
| # --------- | |||||
| DEBUG=True | |||||
| # ---------------- | |||||
| # helper functions | |||||
| # ---------------- | |||||
| def debug(*args): | |||||
| if DEBUG: | |||||
| print(args) | |||||
| # ------------- | |||||
| # main function | |||||
| # ------------- | |||||
| def main(): | |||||
| with open("input7.txt", "r") as file: | |||||
| intext = file.read() | |||||
| # -------------- | |||||
| # run the script | |||||
| # -------------- | |||||
| if __name__ == "__main__": | |||||
| main() |