Welcome

This kata is inspired by This Kata


We have a string s

We have a number n

Here is a function that takes your string, concatenates the even-indexed chars to the front, odd-indexed chars to the back.

Examples

    s = "Wow Example!"
    result = "WwEapeo xml!"
    s = "I'm JomoPipi"
    result = "ImJm ii' ooPp"
    
The Task:

return the result of the string after applying the function to it n times.

example where s = "qwertyuio" and n = 2:

    after 1 iteration  s = "qetuowryi"
    after 2 iterations s = "qtorieuwy"
    return "qtorieuwy"

 Note 

there's a lot of tests, big strings,
and n is greater than a billion

so be ready to optimize.

after doing this: do it's best friend!

# Check out my other kata!

        
Matrix Diagonal Sort OMG
String -> N iterations -> String
String -> X iterations -> String
ANTISTRING
Array - squareUp b!
Matrix - squareUp b!
Infinitely Nested Radical Expressions
pipi Numbers!

Difficulty: EASY
Tags: String algorithms

Ad-hoc

Starter code:
def jumbled_string(s, n):
	

Solutions:
def jumbled_string(s, n):
	iterations = [s]
	while True:
		s = s[::2] + s[1::2]
		if s == iterations[0]:
			break
		iterations.append(s)
	return iterations[n % len(iterations)]


def buildPermList(originalMsg):
	listPerms = []
	listPerms.append(originalMsg)
	curMsg = originalMsg
	while True:
		even = curMsg[0::2]
		odd = curMsg[1::2]
		curMsg = even + odd
		if curMsg != originalMsg:
			listPerms.append(curMsg)
		else:
			break
	return listPerms

def jumbled_string(msg, n):
	permList = buildPermList(msg)
	numUniquePerms = len(permList)
	desiredRotIndex = n % numUniquePerms
	return permList[desiredRotIndex]


def jumbled_string(s, n):
	seen = []
	while s not in seen:
		seen.append(s)
		s = f'{s[::2]}{s[1::2]}'
	return seen[n % len(seen)]


def jumbled_string(s, n):
	ml = ['bullshit']
	new_str = s
	while s != ml[-1]:
		new_str = new_str[::2] + new_str[1::2]
		ml.append(new_str)
	return ml[n % (len(ml) - 1)]


def jumbled_string(s, n):
	mixer = lambda s: s[::2] + s[1::2]
	if n == 1:
		return mixer(s)
	cnt = 1
	x = s
	while s != mixer(x):
		cnt += 1
		x = mixer(x)
	max = n % cnt
	while max != 0:
		s = mixer(s)
		max -= 1
	return s


def jumbled_string(s, n):
	results = [s]
	while n:
		s = s[::2] + s[1::2]
		n -= 1
		if s == results[0]:
			return results[n % len(results)]
		else:
			results.append(s)
	return s


def jumbled_string(s, n):
	a = s
	i = 0
	while i < n:
		s = s[::2] + s[1::2]
		i += 1
		if s == a:
			break
	n = n % i
	for i in range(n):
		s = s[::2] + s[1::2]
	return s


def jumbled_string(s, n):
	idx = list(range(0, len(s), 2)) + list(range(1, len(s), 2))
	lst = []
	while not lst or s != lst[0]:
		lst.append(s)
		s = ''.join((s[i] for i in idx))
		if len(lst) == n:
			return s
	return lst[n % len(lst)]


def jumbled_string(s, n):
	combine = lambda s: s[0::2] + s[1::2]
	for _ in range(n % multiplicativeOrder(2, len(s))):
		s = combine(s)
	return s

def GCD(a, b):
	if b == 0:
		return a
	return GCD(b, a % b)

def multiplicativeOrder(A, N):
	if GCD(A, N) != 1:
		return multiplicativeOrder(A, N - 1)
	result = 1
	K = 1
	while K < N:
		result = result * A % N
		if result == 1:
			return K
		K = K + 1
	return -1


def multiplicativeOrder(b, m):
	(k, r) = (1, 1)
	while True:
		r = r * b % m
		if r == 1:
			return k
		k += 1

def jumbled_string(s, n):
	l = len(s)
	m = l if l & 1 else l - 1
	k = multiplicativeOrder(2, m)
	answer = s
	for i in range(n % k):
		answer = answer[::2] + answer[1::2]
	return answer