# -*- using:utf-8 -*-
import re
def magical_increment(start):
pattern = re.compile(r'[^0-9A-Za-z]')
while True:
yield start
temp = []
add = 1
carry = None
for c in reversed(list(start)):
if pattern.match(c):
temp.append(c)
continue
ch = chr(ord(c) + add)
if c <= '9' < ch:
ch = '0'
carry = '1'
elif c <= 'Z' < ch:
ch = carry = 'A'
elif c <= 'z' < ch:
ch = carry = 'a'
else:
add = 0
carry = None
temp.append(ch)
if carry:
temp.append(carry)
start = ''.join(reversed(temp))
if __name__ == '__main__':
gen = magical_increment('Az-8')
for i in range(5):
print(next(gen))
Es werden nur alphanumerische Zeichen erhöht. Das Symbol bleibt gleich.
Az-8
Az-9
Ba-0
Ba-1
Ba-2
# -*- using:utf-8 -*-
import re
def magical_add(start, step):
pattern = re.compile(r'[^0-9A-Za-z]')
while True:
yield start
temp = []
add = step
prev = ''
for c in reversed(list(start)):
if pattern.match(c):
temp.append(c)
continue
if c <= '9':
value = ord(c) + add % 10
add //= 10
prev = '0'
if ord('9') < value:
value -= 10
add += 1
elif c <= 'Z':
value = ord(c) + add % 26
add //= 26
prev = 'A'
if ord('Z') < value:
value -= 26
add += 1
else:
value = ord(c) + add % 26
add //= 26
prev = 'a'
if ord('z') < value:
value -= 26
add += 1
temp.append(chr(value))
if add:
if prev == '0':
temp.extend(reversed(list(str(add))))
elif prev == 'A' or prev == 'a':
while add:
value = ord(prev) + add % 26 - 1
add //= 26
temp.append(chr(value))
start = ''.join(reversed(temp))
if __name__ == '__main__':
gen = magical_add('aZ-1', 5)
for i in range(5):
print(next(gen))
Es werden nur alphanumerische Zeichen hinzugefügt (in diesem Beispiel werden 5 hinzugefügt). Das Symbol bleibt gleich.
aZ-1
aZ-6
bA-1
bA-6
bB-1
Recommended Posts