## Tuinkaboutersortering

from random import randint;

def is_gesorteerd (lijst):
    index = 1;
    while index < len(lijst) and lijst[index-1] <= lijst[index]:
        index += 1
    return index >= len(lijst)

def sorteer(lijst):
    pos = 1
    while pos < len(lijst):
        if pos == 0 or lijst[pos] >= lijst[pos-1]:
            pos += 1
        else:
            tijdelijk = lijst[pos]
            lijst[pos] = lijst[pos-1]
            lijst[pos-1] = tijdelijk
            pos -= 1
        
for _ in range(1000):
    # een willekeurige lijst van 20 gehele getallen in het bereik [0,30]
    lijst = []
    for __ in range(20):
        lijst.append(randint(0,30))
    sorteer(lijst)
    if not is_gesorteerd(lijst):
        print ("Niet gesorteerd:", lijst)
