Selaa lähdekoodia

Minor Day 6 update

master
Noëlle 1 vuosi sitten
vanhempi
commit
269aa940f4
No known key found for this signature in database
3 muutettua tiedostoa jossa 44 lisäystä ja 8 poistoa
  1. 5
    4
      day6-1.py
  2. 5
    4
      day6-2.py
  3. 34
    0
      day7-1.py

+ 5
- 4
day6-1.py Näytä tiedosto

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


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


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

+ 5
- 4
day6-2.py Näytä tiedosto

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


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


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

+ 34
- 0
day7-1.py Näytä tiedosto

# -------
# 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…
Peruuta
Tallenna