keon / algorithms

Minimal examples of data structures and algorithms in Python
MIT License
23.97k stars 4.6k forks source link

Add Bead Sort Algorithm #920

Open pankaj-bind opened 5 months ago

pankaj-bind commented 5 months ago

please assign me this task

SetareBehzadi commented 1 month ago
def bead_sort(sequence):
    if any(not isinstance(i,int) or i<0 for i in sequence):
        raise TypeErro('must be posetive integer')

    for _ in range(len(sequence)):
        for j,(rod_upper, rod_lower) in enumerate(zip(sequence, sequence[1:])):
            print(j,(rod_upper, rod_lower) )
            if rod_upper > rod_lower:
                sequence[j] -= rod_upper - rod_lower
                sequence[j+1] += rod_upper - rod_lower
            print(f"aaaa {j} : ",sequence)        

    return sequence

I think it is too simple ....