@@ -8,6 +8,7 @@ from string import ascii_letters | |||
# --------- | |||
DEBUG=True | |||
HEADER_LEN = 4 | |||
# ---------------- | |||
# helper functions | |||
@@ -29,14 +30,14 @@ def main(): | |||
for i in range(inlen): | |||
lets = [] | |||
for j in range(4): | |||
for j in range(HEADER_LEN): | |||
clet = intext[i+j] | |||
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: | |||
print(f"Unique! {''.join(lets)} in {i+1}-{i+4}") | |||
print(f"Unique! {''.join(lets)} in {i+1}-{i+HEADER_LEN}") | |||
break | |||
# -------------- |
@@ -8,6 +8,7 @@ from string import ascii_letters | |||
# --------- | |||
DEBUG=True | |||
HEADER_LEN = 14 | |||
# ---------------- | |||
# helper functions | |||
@@ -29,14 +30,14 @@ def main(): | |||
for i in range(inlen): | |||
lets = [] | |||
for j in range(14): | |||
for j in range(HEADER_LEN): | |||
clet = intext[i+j] | |||
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: | |||
print(f"Unique! {''.join(lets)} in {i+1}-{i+14}") | |||
print(f"Unique! {''.join(lets)} in {i+1}-{i+HEADER_LEN}") | |||
break | |||
# -------------- |
@@ -0,0 +1,34 @@ | |||
# ------- | |||
# 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() |