◂ 11 décembre 2015 ▸
Corporate Policy :
- code.py
input = 'hxbxwxba'
INTERDITES = ['i', 'l', 'o']
### Conversions entre chaînes et base 23 ###
def lettreToN(c):
if c in INTERDITES:
return None
return ord(c)-ord('a') - sum([(1 if c > i else 0) for i in INTERDITES])
def nToLettre(n):
n += ord('a')
for c in INTERDITES:
if n >= ord(c):
n += 1
return chr(n)
def stringToTab(s):
# base N, unités en position 0
return list(map(lettreToN, input))[::-1]
def tabToString(t):
return ''.join(map(nToLettre, reversed(t)))
### addition en base N ###
def add(t, n):
N = 26 - len(INTERDITES)
t[0] += n
i = 0
while i < len(t):
if t[i] >= N:
if i+1 >= len(t):
t.append(0)
t[i+1] += t[i] // N
t[i] %= N
else:
break
i += 1
return t
### Critères des mots de passe ###
def okDoublons(t):
nb = 0
i = 0
while i < len(t) - 1:
if t[i] == t[i+1]:
nb += 1
if nb >= 2:
return True
i += 1
i += 1
return False
def okSuite(t):
for i in range(len(t) - 2):
if t[i] == t[i+1] + 1 and t[i+1] == t[i+2] + 1:
return True
return False
### main ###
t = stringToTab(input)
for _ in range(2):
while (not okDoublons(t)) or (not okSuite(t)):
add(t,1)
print(tabToString(t))
add(t,1)