Do day 6.
This commit is contained in:
@@ -5,3 +5,5 @@
|
|||||||
- Day 3: 13:08 actually decent but top 100 required 5:24
|
- Day 3: 13:08 actually decent but top 100 required 5:24
|
||||||
- Day 4: 7:08 but top 100 required 3:33 still okay
|
- Day 4: 7:08 but top 100 required 3:33 still okay
|
||||||
- Day 5: 11:56 but 7:58 for top 100... getting better?
|
- Day 5: 11:56 but 7:58 for top 100... getting better?
|
||||||
|
- Day 6: 3:50 but 2:25 for leaderboard :D
|
||||||
|
- Day 7:
|
||||||
|
|||||||
41
d6.py
Normal file
41
d6.py
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import re
|
||||||
|
from string import ascii_lowercase, ascii_uppercase
|
||||||
|
|
||||||
|
EXAMPLE = """
|
||||||
|
mjqjpqmgbljsphdztnvjfqwrcgsmlb
|
||||||
|
"""
|
||||||
|
|
||||||
|
def clean(text: str) -> list[str]:
|
||||||
|
return list(filter(lambda l: l.strip() != "", text.splitlines()))
|
||||||
|
|
||||||
|
def solve(lines: list[str]):
|
||||||
|
line = lines[0]
|
||||||
|
for i in range(len(lines[0])):
|
||||||
|
l = line[i:i + 4]
|
||||||
|
if len(set(l)) == len(l):
|
||||||
|
return i + 4
|
||||||
|
# 2:55
|
||||||
|
|
||||||
|
def solve2(lines: list[str]):
|
||||||
|
line = lines[0]
|
||||||
|
for i in range(len(lines[0])):
|
||||||
|
l = line[i:i + 14]
|
||||||
|
if len(set(l)) == len(l):
|
||||||
|
return i + 14
|
||||||
|
# 3:50
|
||||||
|
|
||||||
|
def main():
|
||||||
|
example = clean(EXAMPLE)
|
||||||
|
print("Example 1:", solve(example))
|
||||||
|
|
||||||
|
data = clean(open("i6.txt").read())
|
||||||
|
print("Solution 1:", solve(data))
|
||||||
|
|
||||||
|
example = clean(EXAMPLE)
|
||||||
|
print("Example 2:", solve2(example))
|
||||||
|
|
||||||
|
data = clean(open("i6.txt").read())
|
||||||
|
print("Solution 2:", solve2(data))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Reference in New Issue
Block a user