diff --git a/.editorconfig b/.editorconfig index 5b0a40b74..4ea5e2ea9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -135,8 +135,8 @@ indent_size = 4 indent_style = space indent_size = 4 -# Racket -[*.rkt] +# Racket/Scheme +[*.{rkt,ss,scm}] indent_style = space indent_size = 2 diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8baea2e3d..6f8f1e264 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -53,3 +53,5 @@ This file lists everyone, who contributed to this repo and wanted to show up her - James Goytia - Amaras - Jonathan Dönszelmann +- Ishaan Verma +- Delphi1024 diff --git a/README.md b/README.md index 2e3c5223b..e8d947857 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,12 @@ The Arcane Algorithm Archive is a collaborative effort to create a guide for all important algorithms in all languages. This goal is obviously too ambitious for a book of any size, but it is a great project to learn from and work on and will hopefully become an incredible resource for programmers in the future. +To change the language, please use the UI at the top of the site: + +

+ +

+ Here are some essential links: - Book / website: diff --git a/contents/bogo_sort/bogo_sort.md b/contents/bogo_sort/bogo_sort.md index cc8e9ce2a..5f493e0e1 100644 --- a/contents/bogo_sort/bogo_sort.md +++ b/contents/bogo_sort/bogo_sort.md @@ -69,6 +69,8 @@ In code, it looks something like this: [import:12-16, lang:"scala"](code/scala/bogo.scala) {% sample lang="go" %} [import:27-31, lang:"go"](code/go/bogo_sort.go) +{% sample lang="coco" %} +[import:6-8, lang:"coconut"](code/coconut/bogo.coco) {% endmethod %} That's it. @@ -137,6 +139,8 @@ We are done here! [import, lang:"scala"](code/scala/bogo.scala) {% sample lang="go" %} [import, lang:"go"](code/go/bogo_sort.go) +{% sample lang="coco" %} +[import, lang:"coconut"](code/coconut/bogo.coco) {% endmethod %} diff --git a/contents/bogo_sort/code/coconut/bogo.coco b/contents/bogo_sort/code/coconut/bogo.coco new file mode 100644 index 000000000..bc467bafb --- /dev/null +++ b/contents/bogo_sort/code/coconut/bogo.coco @@ -0,0 +1,15 @@ +import random + + +is_sorted = l -> (l, l[1:]) |*> zip |> map$(t -> t[0] <= t[1]) |> all + +def bogo_sort(a): + while not is_sorted(a): + random.shuffle(a) + + +if __name__ == '__main__': + a = [1, 3, 2, 4] + print('Unsorted:', a) + bogo_sort(a) + print('Sorted:', a) diff --git a/contents/bogo_sort/code/nim/bogo_sort.nim b/contents/bogo_sort/code/nim/bogo_sort.nim index aca98f749..9f4838a6c 100644 --- a/contents/bogo_sort/code/nim/bogo_sort.nim +++ b/contents/bogo_sort/code/nim/bogo_sort.nim @@ -3,24 +3,23 @@ import random randomize() proc print_array(a: openArray[int]) = - for n in 0 .. len(a)-1: - echo a[n] + for n in 0 .. len(a)-1: + echo a[n] -proc is_sorted(a: openArray[int]): bool = - for n in 1 .. len(a)-1: - if a[n] > a[n-1]: - return false - - return true +func is_sorted(a: openArray[int]): bool = + result = true + for n in 1 .. len(a)-1: + if a[n] > a[n-1]: + result = false + break proc bogo_sort(a: var openArray[int]) = - while not is_sorted(a): - shuffle(a) - + while not is_sorted(a): + shuffle(a) -var x: array[10,int] = [32,32,64,16,128,8,256,4,512,2] - -print_array(x) -bogo_sort(x) -echo "\n" -print_array(x) +when isMainModule: + var x = [32, 32, 64, 16, 128, 8, 256, 4, 512, 2] + print_array(x) + bogo_sort(x) + echo "\n" + print_array(x) diff --git a/contents/bubble_sort/bubble_sort.md b/contents/bubble_sort/bubble_sort.md index 8b5b6b8e8..27071de4a 100644 --- a/contents/bubble_sort/bubble_sort.md +++ b/contents/bubble_sort/bubble_sort.md @@ -78,6 +78,8 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with [import:1-6, lang:"coffeescript"](code/coffeescript/bubblesort.coffee) {% sample lang="r" %} [import:1-12, lang:"r"](code/r/bubble_sort.R) +{% sample lang="coco" %} +[import:3-10, lang:"coconut"](code/coconut/bubblesort.coco) {% endmethod %} ... And that's it for the simplest bubble sort method. @@ -159,6 +161,8 @@ The code snippet was taken from this [Scratch project](https://scratch.mit.edu/p [import, lang:"coffeescript"](code/coffeescript/bubblesort.coffee) {% sample lang="r" %} [import, lang:"r"](code/r/bubble_sort.R) +{% sample lang="coco" %} +[import, lang:"coconut"](code/coconut/bubblesort.coco) {% endmethod %}