-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.b.py
More file actions
40 lines (33 loc) · 1.1 KB
/
11.b.py
File metadata and controls
40 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
with open("2015/11.input.txt", encoding="utf-8") as file:
data = file.read()
old = [ord(c) - 97 for c in reversed(data.strip())]
def incr(a: list[int]):
for i, c in enumerate(a):
if c == 25:
a[i] = 0
else:
a[i] += 1
return
while True:
incr(old)
# remember old is reversed
if any(
b - a == 1 and c - b == 1
for c, b, a in zip(old, old[1:], old[2:])
# i l o
) and not any(c in old for c in [8, 11, 14]):
pairs = [a == b for a, b in zip(old, old[1:])]
if any(x and any(pairs[i + 2 :]) for i, x in enumerate(pairs)):
break
while True:
incr(old)
# remember old is reversed
if any(
b - a == 1 and c - b == 1
for c, b, a in zip(old, old[1:], old[2:])
# i l o
) and not any(c in old for c in [8, 11, 14]):
pairs = [a == b for a, b in zip(old, old[1:])]
if any(x and any(pairs[i + 2 :]) for i, x in enumerate(pairs)):
break
print("".join(chr(c + 97) for c in reversed(old)))