From: Skullheadx <704277@pdsb.net> Date: Wed, 25 Jan 2023 03:48:53 +0000 (-0500) Subject: Create bogo_sort.py X-Git-Url: http://git.skullheadx.com/nixos/static/gitweb.js?a=commitdiff_plain;h=f9f766ff81cf58e5d39e6ccd569a1cf115fd4723;p=Sorting.git Create bogo_sort.py --- diff --git a/sorting_algorithms/bogo_sort.py b/sorting_algorithms/bogo_sort.py new file mode 100644 index 0000000..0f7b91b --- /dev/null +++ b/sorting_algorithms/bogo_sort.py @@ -0,0 +1,10 @@ +# Bogo Sort (O(n*n!)) +from random import sample +from utils import swap, is_increasing + + +def bogo_sort(array): + while not is_increasing(array): + a, b = sample(range(len(array)), 2) + swap(array, a, b) + return array