#Split all even numbers to odd ones in different ways

Your task is to split all even numbers from an array to odd ones. So your method has to return a new array with only odd numbers.

For "splitting" the numbers there are four ways.

```
0 -> Split into two odd numbers, that are closest to each other.
     (e.g.: 8 -> 3,5)
1 -> Split into two odd numbers, that are most far from each other.
     (e.g.: 8 -> 1,7)
2 -> All new odd numbers from the splitting should be equal and the maximum possible number.
     (e.g.: 8 -> 1, 1, 1, 1, 1, 1, 1, 1)
3 -> Split into 1s.
     (e.g.: 8 -> 1, 1, 1, 1, 1, 1, 1, 1)
The new numbers (from the splitting) have always to be in ascending order.
So in the array every even number is replaced by the new odd numbers from the splitting.
```

Your method will get as parameters the input-array and the number of the way for splitting the even numbers.

Some Examples
```
[1,10,1,3],0 -> [1,5,5,1,3]
[1,10,1,3],1 -> [1,1,9,1,3]
[1,10,1,3],2 -> [1,5,5,1,3]
[1,10,1,3],3 -> [1,1,1,1,1,1,1,1,1,1,1,1,3]

[1,1,3,8],0 -> [1,1,3,3,5]
[1,1,3,8],1 -> [1,1,3,1,7]
[1,1,3,8],2 -> [1,1,3,1,1,1,1,1,1,1,1]
[1,1,3,8],3 -> [1,1,3,1,1,1,1,1,1,1,1]
```

The array will never be null and will always contain only integer numbers > 0. Also your result-array must contain only integer numbers > 0.
The way-parameter will always be between inclusive 0 and inclusive 3 (0,1,2,3).

You must not change the input-array!


Have fun coding it and please don't forget to vote and rank this kata! :-) 

I have also created other katas. Take a look if you enjoyed this kata!

Difficulty: introductory

Starter code:

def split_all_even_numbers(numbers, way):
	

Solutions:
def split_all_even_numbers(numbers, split_type):
    result = []
    for a in numbers:
        if a % 2:
            result.append(a)
        else:
            pairs = [(b, a - b) for b in range(1, a // 2 + 1, 2) if a - b % 2]
            if split_type == 0:
                result.extend(pairs[-1])
            elif split_type == 1:
                result.extend(pairs[0])
            elif split_type == 2:
                for c, _ in reversed(pairs):
                    quo, rem = divmod(a, c)
                    if not rem:
                        result.extend([c] * quo)
                        break
            elif split_type == 3:
                result.extend([1] * a)
    return result


from itertools import chain

def split_all_even_numbers(lst, way):

    def convert(n):
        s = 1 - (n//2) % 2                               # Shift for closest odd numbers
        return ([n]              if n%2 else             # Is already odd
                [n//2-s, n//2+s] if way == 0 else        # Two closest odd sum
                [1,n-1]          if way == 1 else        # Two farthest odd sum
                [1]*n            if way == 3 else        # Split in ones
                split_all_even_numbers([n//2]*2, 2))     # Split in highest possible odds
    
    return list(chain(*map(convert, lst)))

def split_even_number0(n):
    if not n % 4:
        return [n / 2 - 1,n / 2 + 1]
    return [n / 2,n / 2]

def split_even_number1(n):
    return [1,n - 1]

def split_even_number2(n):
    times = 1
    tmp = n
    while not tmp % 2:
        tmp /= 2
        times *= 2
    return [tmp] * times

def split_even_number3(n):
    return [1] * n

def split_all_even_numbers(numbers, way):
    result = []
    for i in numbers:
        if i % 2:
            result += [i]
        else:
            if way == 0:
                result += split_even_number0(i)
            elif way == 1:
                result += split_even_number1(i)
            elif way == 2:
                result += split_even_number2(i)
            else:
                result += split_even_number3(i)
    return result

def split_all_even_numbers(numbers, way):
    split = (split_closest, split_furthest, split_max_equal, split_ones)[way]
    return sum(([n] if n % 2 else split(n) for n in numbers), [])


split_closest = lambda n: [n//2 + s * (n%4 == 0) for s in (-1, 1)]
split_furthest = lambda n: [1, n-1]
split_max_equal = lambda n: [n] if n % 2 else split_max_equal(n // 2) * 2
split_ones = lambda n: [1 for _ in range(n)]

split0 = lambda x: [x] if x&1 else [(x>>1) - ((x&2)>>1^1), (x>>1) + ((x&2)>>1^1)]
split1 = lambda x: [x] if x&1 else [1, x-1]
split2 = lambda x: [x] if x&1 else split2(x>>1)*2
split3 = lambda x: [x] if x&1 else [1]*x

splits = (split0, split1, split2, split3)

def split_all_even_numbers(numbers, way):
    return [y for x in numbers for y in splits[way](x)]

def split_all_even_numbers(arr, way):
    if way==0 : return sum([[[(i//2)-(not(i//2)&1),(i//2)+(not(i//2)&1)],[i]][i&1] for i in arr],[])
    if way==1 : return sum([[[1, i - 1],[i]][i&1] for i in arr],[])
    if way == 2:
        li = []
        for i in arr:
            if not i & 1:
                a, b = next([k, i // k] for k in range(i - 1, 0, -1) if i % k == 0 and k & 1)
                li.extend([a] * b)
            else : li.append(i)
        return li
    return sum([[[1] * i,[i]][i&1] for i in arr],[])

from itertools import chain

def f1(n):
    x = n // 2
    if x % 2:
        return x, n-x
    else:
        return x-1, x+1

def f3(n):
    m = n
    while m % 2 == 0:
        m //= 2
    return [m] * (n // m)

fs = [f1, lambda n: [1, n-1], f3, lambda n: [1] * n]

def split_all_even_numbers(numbers, way):
    return list(chain.from_iterable([n] if n % 2 else fs[way](n) for n in numbers))

ways = {
    0 : lambda n : [n//2]*2 if (n//2)%2 else [n//2-1,n//2+1],
    1 : lambda n : [1,n-1],
    2 : lambda n : [ [n//x]*x for x in range(2,n+1) if sum([n//x]*x)==n and (n//x)%2][0],
    3 : lambda n : [1]*n
}

def split_all_even_numbers(numbers, way):
  return [x for lists in [ways[way](x) if not x%2 else [x] for x in numbers] for x in lists]

def even(n):
    return n % 2 == 0

def split_all_even_numbers(numbers, way):
    lst = []
    for n in numbers:
        if even(n): lst += split(n, way)
        else: lst += [n]
    return lst                
        
def split(num, way):  
    if way == 0:
        half = num / 2
        return [half-1, half+1] if even(half) else [half, half]
    elif way == 1:
        return [1, num - 1]
    elif way == 2:
        return next([d] * (num // d) for d in range(num-1, 0, -2) if num % d == 0)
    elif way == 3:
        return [1] * num

def split_all_even_numbers(numbers, way):
    def split0(n): return (n // 2, n // 2) if n//2 % 2 else (n//2 - 1, n//2 + 1)
    def split1(n): return 1, n-1
    def split2(n):
        ctr = 0
        while n % 2 == 0:
            ctr, n = ctr + 1, n//2
        return [n]*(2**ctr)
    def split3(n): return [1]*n
    split_ops = [split0, split1, split2, split3]
    return [x for lst in [split_ops[way](n) if n % 2 == 0 else [n] for n in numbers] for x in lst]