advent/2015/5/sol2.py
2022-11-06 13:55:53 -06:00

44 lines
854 B
Python

files = [i.rstrip() for i in open("input").readlines()]
def naughtyornice(string):
last = None
lastlast = None
c1 = False
c2 = False
for i in string:
if i == lastlast:
c2 = True
lastlast = last
last = i
collections = []
for i in range(len(string)):
try:
collections.append((string[i], string[i + 1], i))
except IndexError:
pass
res = []
for i in collections:
for j in collections:
if not i == j and i[0] == j[0] and i[1] == j[1] and i[2] != j[2] + 1 and j[2] != i[2] + 1:
res.append("".join([i[0], i[1]]))
res = set(res)
if len(res) > 0:
c1 = True
print(res)
return c1 and c2
nicecount = 0
for i in files:
if naughtyornice(i):
nicecount += 1
print(nicecount)