diff --git a/allalgorithms/sorting/BogoSort.py b/allalgorithms/sorting/BogoSort.py new file mode 100644 index 0000000..bafbb9b --- /dev/null +++ b/allalgorithms/sorting/BogoSort.py @@ -0,0 +1,17 @@ +# -*- coding: UTF-8 -*- +# +# BogoSort Algorithm +# The All â–²lgorithms library for python +# +# Contributed by: Cayo Viegas +# Github: @CayoViegas +# + +from random import shuffle + +def bogosort(seq): + while not all(x <= y for x, y in zip(seq, seq[1:])): + shuffle(seq) + + return seq +