From f9f766ff81cf58e5d39e6ccd569a1cf115fd4723 Mon Sep 17 00:00:00 2001 From: Skullheadx <704277@pdsb.net> Date: Tue, 24 Jan 2023 22:48:53 -0500 Subject: [PATCH] Create bogo_sort.py --- sorting_algorithms/bogo_sort.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 sorting_algorithms/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 -- 2.54.0