Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Sequence Analyzer by kdim
def analyzer(s):
diff = lambda x, y: (ord(x) - ord(y)) % 26
is_sequence = lambda x: len(set(diff(i, j) for i, j in zip(x, x[1:]))) == 1
next_sequence = lambda y: [chr(65 + (diff(y[-1], 'A') - (i + 1) * diff(*y[:2])) % 26) for i in range(len(y))]
if is_sequence(s[::1]):
s = next_sequence(s)
elif is_sequence(s[::2]):
s = [next_sequence(s[::2]), next_sequence(s[1::2])]
else:
s = [next_sequence(s[::3]), next_sequence(s[1::3]), next_sequence(s[2::3])]
return ''.join(sum(list(zip(*s)), ()))
Nov. 18, 2024