def triFusion(L):
def fusion(A,B):
if len(A) == 0:
return B
elif len(B) == 0:
return A
elif A[0] <= B[0]:
return [A[0]] + fusion( A[1:] , B )
else:
return [B[0]] + fusion( A , B[1:] )
if len(L) == 1:
return L
else:
return fusion( triFusion(L[:len(L)//2]) , triFusion(L[len(L)//2:]) )
import codewars_test as test
from random import randint as rn
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
for _ in range(20):
l = [rn(0, 1000) for _ in range(10)]
sorted = l
sorted.sort()
test.assert_equals(triFusion(l), sorted)