Created
December 5, 2018 19:17
-
-
Save wakemaster39/ffe7e1af0cabfb94809be204ebba2c9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
import functools | |
from aocd import get_data | |
DAY=5 | |
dir = os.path.dirname(__file__) | |
directory = os.path.join(dir, f"day{DAY}") | |
if not os.path.exists(directory): | |
os.makedirs(directory) | |
if not os.path.exists(os.path.join(directory, "data.txt")): | |
with open(os.path.join(dir, "../../" "config", "session")) as f: | |
session = f.read()[:-1] | |
data = get_data(session=session, day=DAY, year=2018) | |
with open(os.path.join(directory, "data.txt"), "w+") as f: | |
f.write(data) | |
else: | |
with open(os.path.join(directory, "data.txt")) as f: | |
data = f.read() | |
import string | |
import re | |
r = functools.reduce(lambda x,y: f'{x}|{y}' ,map(lambda x: f'{x}{x.upper()}|{x.upper()}{x}', string.ascii_lowercase)) | |
regex = f"({r})" | |
length = [] | |
for x in string.ascii_lowercase: | |
cdata = data | |
cdata = re.sub(f"{x}|{x.upper()}", "", cdata) | |
while True: | |
if re.search(r, cdata): | |
print(len(cdata)) | |
cdata = re.sub(regex,"", cdata) | |
else: | |
break | |
length.append(len(cdata)) | |
print(min(length)) |
zero-code-hero
commented
Dec 5, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment