day 6
This commit is contained in:
parent
7660607c7c
commit
d34efaa5d1
|
@ -0,0 +1,8 @@
|
|||
import sys
|
||||
|
||||
L = sys.stdin.read()
|
||||
|
||||
for (i, (a,b,c,d)) in enumerate(zip(L,L[1:],L[2:],L[3:])):
|
||||
if not (b == a or c == a or c == b or d == a or d == b or d == c):
|
||||
print(i+4, L[i:i+4])
|
||||
break
|
|
@ -0,0 +1,23 @@
|
|||
import sys
|
||||
|
||||
def window_iter(it, size):
|
||||
from itertools import tee
|
||||
wt = tee(it, size) # tuple(n iterables)
|
||||
# shift each iterator by its place in the window
|
||||
for (i,x) in enumerate(wt):
|
||||
for _ in range(i):
|
||||
next(x)
|
||||
while True:
|
||||
try:
|
||||
yield tuple(next(x) for x in wt)
|
||||
except RuntimeError: # RuntimeError: generator raised StopIteration
|
||||
break
|
||||
|
||||
L = sys.stdin.read()
|
||||
|
||||
from itertools import combinations as comb
|
||||
|
||||
for (i, T) in enumerate(window_iter(L,14)):
|
||||
if all(map(lambda x: x[0] != x[1], comb(T,2))):
|
||||
print(i+14, L[i:i+14])
|
||||
break
|
|
@ -0,0 +1,13 @@
|
|||
import sys
|
||||
from collections import deque
|
||||
|
||||
dq = deque()
|
||||
for (i,c) in enumerate(sys.stdin.read()):
|
||||
equals = list(filter(lambda x: c == x[1], enumerate(dq)))
|
||||
if len(equals)>0: # remove left part until a char equal to c, included
|
||||
for _ in range(equals[-1][0]+1):
|
||||
dq.popleft()
|
||||
if len(dq) == 13: # if we have 13+1 distinct chars, we're good
|
||||
print(i+1)
|
||||
break
|
||||
dq.append(c)
|
|
@ -0,0 +1,6 @@
|
|||
import sys
|
||||
s = sys.stdin.read()
|
||||
for i in range(14, len(s)):
|
||||
if len(set(s[i-14:i])) == 14:
|
||||
print(i)
|
||||
break
|
Loading…
Reference in New Issue