Browse Source

Minor Day 6 update

master
Noëlle 1 year ago
parent
commit
269aa940f4
No known key found for this signature in database
3 changed files with 44 additions and 8 deletions
  1. 5
    4
      day6-1.py
  2. 5
    4
      day6-2.py
  3. 34
    0
      day7-1.py

+ 5
- 4
day6-1.py View File

@@ -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

# --------------

+ 5
- 4
day6-2.py View File

@@ -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

# --------------

+ 34
- 0
day7-1.py View File

@@ -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()

Loading…
Cancel
Save