2015/day11.py

45 lines
910 B
Python

input = "cqjxjnds"
pw = [ord(c) - ord("a") for c in input]
pw[-1] += 1
part1, part2 = None, None
while not part2:
# increment pw
pw[-1] += 1
for i in range(len(pw) - 1, 0, -1):
if pw[i] >= 26:
pw[i - 1] += 1
pw[i] = 0
else:
break
if 8 in pw:
pw[pw.index(8)] += 1
if 11 in pw:
pw[pw.index(11)] += 1
if 14 in pw:
pw[pw.index(14)] += 1
for i in range(len(pw) - 2):
if pw[i] + 2 == pw[i + 1] + 1 == pw[i + 2]:
break
else:
continue
pairs = 0
for i in range(len(pw) - 1):
c = pw[i]
if c == pw[i + 1] and (i == 0 or c != pw[i - 1]):
pairs += 1
if pairs < 2:
continue
if not part1:
part1 = "".join(chr(c + ord("a")) for c in pw)
else:
part2 = "".join(chr(c + ord("a")) for c in pw)
print(part1, part2)