Skip to content

Instantly share code, notes, and snippets.

@darighost
Last active May 26, 2023 00:24
Show Gist options
  • Save darighost/9686467d3f833345ec1d039470c3cca9 to your computer and use it in GitHub Desktop.
Save darighost/9686467d3f833345ec1d039470c3cca9 to your computer and use it in GitHub Desktop.
Selection sort in Scratch (bored at McDonald's)

I'm teaching kids Scratch, which means I need to learn it!

This program asks for a list of numbers, then prints the sorted result.

Screen Shot 2023-05-25 at 12 48 36

Eg if we give it the numbers 1488, 9001, 666, 777, and 13, and 12, it gives us:

Screen Shot 2023-05-25 at 12 59 27

The sorted list appears in the bottom right corner.

Originally, I called this "insertion sort", but actually I realized it is selection sort.

To demonstrate why block-based visual programming is maybe not the future, here's how easy this is in Python:

def selection_sort_r(lst): 
    if lst:
        yield min(lst)
        lst.remove(min(lst))
        yield from selection_sort_r(lst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment