From 09aa94ed128294dfb0582723e8535335eb049bcf Mon Sep 17 00:00:00 2001 From: Kjetil Andre Johannessen Date: Thu, 28 Jun 2018 09:09:02 +0200 Subject: [PATCH 1/2] Added contributor --- CONTRIBUTORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 04ec1f0fd..589b7db37 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -9,3 +9,4 @@ Maxime Dherbécourt Jess 3Jane Pen Pal Chinmaya Mahesh +Kjetil Johannessen From d2d26842240662784f727fe474b8eff43cf2edb8 Mon Sep 17 00:00:00 2001 From: Kjetil Andre Johannessen Date: Thu, 28 Jun 2018 10:16:50 +0200 Subject: [PATCH 2/2] Added python bogosort --- chapters/sorting_searching/bogo/bogo_sort.md | 2 ++ .../bogo/code/python/bogo.py | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 chapters/sorting_searching/bogo/code/python/bogo.py diff --git a/chapters/sorting_searching/bogo/bogo_sort.md b/chapters/sorting_searching/bogo/bogo_sort.md index e8c91fec2..a222dbdcb 100644 --- a/chapters/sorting_searching/bogo/bogo_sort.md +++ b/chapters/sorting_searching/bogo/bogo_sort.md @@ -25,6 +25,8 @@ In code, it looks something like this: [import:2-17, lang:"java"](code/java/bogo.java) {% sample lang="js" %} [import:1-16, lang:"javascript"](code/js/bogo.js) +{% sample lang="py" %} +[import:4-12, lang:"python"](code/python/bogo.py) {% sample lang="hs" %} [import, lang:"haskell"](code/haskell/bogoSort.hs) {% sample lang="cpp" %} diff --git a/chapters/sorting_searching/bogo/code/python/bogo.py b/chapters/sorting_searching/bogo/code/python/bogo.py new file mode 100644 index 000000000..eaf9f4933 --- /dev/null +++ b/chapters/sorting_searching/bogo/code/python/bogo.py @@ -0,0 +1,20 @@ +import random + + +def is_sorted(a): + for i in range(len(a)-1): + if a[i+1] < a[i]: + return False + return True + +def bogo_sort(a): + while not is_sorted(a): + random.shuffle(a) + +def main(): + a = [1., 3, 2, 4] + bogo_sort(a) + print(a) + +main() +