summary refs log tree commit diff stats
path: root/day11.py
blob: 534b6c40e6850bed53095014ecb2387d6fdf36e4 (plain) (blame)
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
41
42
#!/usr/bin/env python

from itertools import combinations

def valid(password):
    def windows():
        alphabet = 'abcdefghijklmnopqrstuvwxyz'
        for i in range(24):
            yield alphabet[i:i+3]

    def pairs():
        alphabet = 'abcdefghijklmnopqrstuvwxyz'
        for combo in combinations(alphabet, 2):
            yield combo

    if not any(seq in password for seq in windows()):
        return False
    if any(char in password for char in 'iol'):
        return False
    if not any(char1*2 in password and char2*2 in password for char1, char2 in pairs()):
        return False
    return True



def passwords():
    password = list(map(lambda x: ord(x)-96, 'cqjxjnds'))
    while not password[0] == 27:
        yield ''.join(char for char in map(lambda x: chr(x+96), password))
        password[-1] += 1
        for i in range(7, 0, -1):
            if password[i] == 27:
                password[i] = 1
                password[i-1] += 1

count = 0
for password in passwords():
    if valid(password):
        print(password)
        count += 1
        if count == 2:
            break