]> Skullheadx's Git Forge - Sorting.git/commitdiff
Create bogo_sort.py
authorSkullheadx <704277@pdsb.net>
Wed, 25 Jan 2023 03:48:53 +0000 (22:48 -0500)
committerSkullheadx <704277@pdsb.net>
Wed, 25 Jan 2023 03:48:53 +0000 (22:48 -0500)
sorting_algorithms/bogo_sort.py [new file with mode: 0644]

diff --git a/sorting_algorithms/bogo_sort.py b/sorting_algorithms/bogo_sort.py
new file mode 100644 (file)
index 0000000..0f7b91b
--- /dev/null
@@ -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