Test Setup Failed
Push — master ( 4d4b20...c9b520 )
by Ken M.
01:01
created

get_password()   B

Complexity

Conditions 6

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
dl 0
loc 6
rs 8
c 0
b 0
f 0
1
import itertools
2
3
4
def get_password(cipher_grille, ciphered_password):
5
    flat_grille = [True if j == 'X' else False
6
                   for i in cipher_grille
7
                   for j in i]
8
    flat_password = [j for i in ciphered_password for j in i]
9
    return ''.join(itertools.compress(flat_password, flat_grille))
10
11
12
def recall_password(cipher_grille, ciphered_password):
13
    password = ''
14
    for i in range(4):
15
        password += get_password(cipher_grille, ciphered_password)
16
        cipher_grille = list(map(lambda x: ''.join(x),
17
                                 zip(*cipher_grille[::-1])))
18
    return password
19
20
21
if __name__ == '__main__':
22
    # These "asserts" using only for self-checking and not necessary for
23
    # auto-testing
24
    assert recall_password(
25
        ('X...',
26
         '..X.',
27
         'X..X',
28
         '....'),
29
        ('itdf',
30
         'gdce',
31
         'aton',
32
         'qrdi')) == 'icantforgetiddqd', 'First example'
33
34
    assert recall_password(
35
        ('....',
36
         'X..X',
37
         '.X..',
38
         '...X'),
39
        ('xhwc',
40
         'rsqx',
41
         'xqzz',
42
         'fyzr')) == 'rxqrwsfzxqxzhczy', 'Second example'
43