Day 6 completed, part1.py is now executable
This commit is contained in:
parent
ae98a486a9
commit
d800679291
3
day6/common.py
Normal file
3
day6/common.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
def parse(filename: str):
|
||||||
|
with open(filename) as f:
|
||||||
|
return f.readline()[:-1]
|
20
day6/part1.py
Normal file
20
day6/part1.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from common import parse
|
||||||
|
|
||||||
|
|
||||||
|
def all_different_characters(input: str) -> bool:
|
||||||
|
return all(map(lambda c: input.count(c) == 1, input))
|
||||||
|
|
||||||
|
|
||||||
|
def solve(input: str) -> int:
|
||||||
|
i = 0
|
||||||
|
while i < len(input) and not all_different_characters(input[i : i + 4]):
|
||||||
|
i += 1
|
||||||
|
return i + 4
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print(solve(parse("input")))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
20
day6/part2.py
Normal file
20
day6/part2.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from common import parse
|
||||||
|
|
||||||
|
|
||||||
|
def all_different_characters(input: str) -> bool:
|
||||||
|
return all(map(lambda c: input.count(c) == 1, input))
|
||||||
|
|
||||||
|
|
||||||
|
def solve(input: str) -> int:
|
||||||
|
i = 0
|
||||||
|
while i < len(input) and not all_different_characters(input[i : i + 14]):
|
||||||
|
i += 1
|
||||||
|
return i + 14
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print(solve(parse("input")))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
1
template/part1.py
Normal file → Executable file
1
template/part1.py
Normal file → Executable file
@ -1,3 +1,4 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
from common import parse
|
from common import parse
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user