Skip to content

Commit 434f6e9

Browse files
authored
Merge branch 'master' into patch-2
2 parents 932ae1e + 61cf9ef commit 434f6e9

File tree

98 files changed

+3884
-1094
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+3884
-1094
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Contributing
2+
3+
A contribution guide on how to contribute to the Arcane Algorithm Archive (AAA) can be found on this Wiki page:
4+
https://github.com/algorithm-archivists/algorithm-archive/wiki/How-to-Contribute
5+
6+
The community member Buttercak3 also created a video series, explaining the contribution process of the AAA.
7+
You can find a playlist with all videos here:
8+
https://www.youtube.com/playlist?list=PL5NSPcN6fRq2vwgdb9noJacF945CeBk8x

CONTRIBUTORS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
This file lists everyone, who contributed to this repo and wanted to show up here. If you're looking for information on contribution, please check the `CONTRIBUTING.md` out.
2+
3+
# Contributors
4+
15
James Schloss
26
<br>
37
Nicole Mazzuca
@@ -44,3 +48,10 @@ Max Weinstein
4448
<br>
4549
Gibus Wearing Brony
4650
<br>
51+
Gorzoid
52+
<br>
53+
Arun Sahadeo
54+
<br>
55+
NIFR91
56+
<br>
57+
Michal Hanajik

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ and live coded on Twitch: https://www.twitch.tv/simuleios.
1515
If you would like to communicate more directly, please feel free to go to our discord: https://discord.gg/Pr2E9S6.
1616

1717

18-
Note that the this project is is essentially a book about algorithms collaboratively written by an online community.
18+
Note that the this project is essentially a book about algorithms collaboratively written by an online community.
1919
Fortunately, there are a lot of algorithms out there, which means that there is a lot of content material available.
2020
Unfortunately, this means that we will probably never cover every algorithm ever created and instead need to focus on what the community sees as useful and necessary.
2121
That said, we'll still cover a few algorithms for fun that have very little, if any practical purpose.
2222

2323
If you would like to contribute, feel free to go to any chapter with code associated with it and implement that algorithm in your favorite language,
24-
and then submit the code via pull request, following the submission guidelines found in `contents/how_to_contribute/how_to_contribute.md` (or [here](contents/how_to_contribute/how_to_contribute.md) if you are reading this on gitbook).
24+
and then submit the code via pull request, following the submission guidelines found in `contents/how_to_contribute/how_to_contribute.md` (or [here](contents/how_to_contribute/how_to_contribute.md) if you are reading this on GitBook).
2525

2626
Hopefully, this project will grow and allow individuals to learn about and try their hand at implementing different algorithms for fun and (potentially) useful projects.
2727
If nothing else, it will be an enjoyable adventure for our community.

book.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"gitbook": "3.x.x",
33
"plugins": [
44
"fontsettings",
5-
"mathjax",
5+
"mathjax@https://github.com/algorithm-archivists/plugin-mathjax",
66
"bibtex-cite",
77
"creativecommons",
88
"wordcount",
@@ -15,6 +15,9 @@
1515
"maxIndexSize": 1000000000
1616
},
1717
"pluginsConfig": {
18+
"mathjax":{
19+
"version": "2.6.1"
20+
},
1821
"include-codeblock": {
1922
"fixlang": true,
2023
"unindent": true
@@ -33,10 +36,6 @@
3336
"name": "Julia",
3437
"default": true
3538
},
36-
{
37-
"lang": "pseudo",
38-
"name": "Pseudocode"
39-
},
4039
{
4140
"lang": "cs",
4241
"name": "C#"
@@ -116,6 +115,18 @@
116115
{
117116
"lang": "ti83b",
118117
"name": "TI-83 Basic"
118+
},
119+
{
120+
"lang": "lua",
121+
"name": "Lua"
122+
},
123+
{
124+
"lang": "crystal",
125+
"name": "Crystal"
126+
},
127+
{
128+
"lang": "php",
129+
"name": "PHP"
119130
}
120131
]
121132
}

contents/backward_euler_method/backward_euler_method.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,3 @@ MORE TO COME!!!
88
<script>
99
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
1010
</script>
11-
$$
12-
\newcommand{\d}{\mathrm{d}}
13-
\newcommand{\bff}{\boldsymbol{f}}
14-
\newcommand{\bfg}{\boldsymbol{g}}
15-
\newcommand{\bfp}{\boldsymbol{p}}
16-
\newcommand{\bfq}{\boldsymbol{q}}
17-
\newcommand{\bfx}{\boldsymbol{x}}
18-
\newcommand{\bfu}{\boldsymbol{u}}
19-
\newcommand{\bfv}{\boldsymbol{v}}
20-
\newcommand{\bfA}{\boldsymbol{A}}
21-
\newcommand{\bfB}{\boldsymbol{B}}
22-
\newcommand{\bfC}{\boldsymbol{C}}
23-
\newcommand{\bfM}{\boldsymbol{M}}
24-
\newcommand{\bfJ}{\boldsymbol{J}}
25-
\newcommand{\bfR}{\boldsymbol{R}}
26-
\newcommand{\bfT}{\boldsymbol{T}}
27-
\newcommand{\bfomega}{\boldsymbol{\omega}}
28-
\newcommand{\bftau}{\boldsymbol{\tau}}
29-
$$
30-

contents/barnes_hut_algorithm/barnes_hut_algorithm.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,3 @@ TODO
1111
<script>
1212
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
1313
</script>
14-
$$
15-
\newcommand{\d}{\mathrm{d}}
16-
\newcommand{\bff}{\boldsymbol{f}}
17-
\newcommand{\bfg}{\boldsymbol{g}}
18-
\newcommand{\bfp}{\boldsymbol{p}}
19-
\newcommand{\bfq}{\boldsymbol{q}}
20-
\newcommand{\bfx}{\boldsymbol{x}}
21-
\newcommand{\bfu}{\boldsymbol{u}}
22-
\newcommand{\bfv}{\boldsymbol{v}}
23-
\newcommand{\bfA}{\boldsymbol{A}}
24-
\newcommand{\bfB}{\boldsymbol{B}}
25-
\newcommand{\bfC}{\boldsymbol{C}}
26-
\newcommand{\bfM}{\boldsymbol{M}}
27-
\newcommand{\bfJ}{\boldsymbol{J}}
28-
\newcommand{\bfR}{\boldsymbol{R}}
29-
\newcommand{\bfT}{\boldsymbol{T}}
30-
\newcommand{\bfomega}{\boldsymbol{\omega}}
31-
\newcommand{\bftau}{\boldsymbol{\tau}}
32-
$$
33-

contents/bitlogic/bitlogic.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ There are more complicated things that can be done with the bitshift operators;
9292

9393
#### Logic gates
9494
In addition to the bitshift operations, there are a number of logical operations that can be performed on one or two bits together.
95-
These operations are called *gates*, and follow soemwhat straightforward logic.
95+
These operations are called *gates*, and follow somewhat straightforward logic.
9696
The *AND* gate, for example, reads in 2 bits and will only output a 1 value if both inputs are 1. This can be seen in the corresponding truth table:
9797

9898
<p>
@@ -136,23 +136,3 @@ That's about it for bitlogic. I realize it was a bit long, but this is absolutel
136136
<script>
137137
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
138138
</script>
139-
$$
140-
\newcommand{\d}{\mathrm{d}}
141-
\newcommand{\bff}{\boldsymbol{f}}
142-
\newcommand{\bfg}{\boldsymbol{g}}
143-
\newcommand{\bfp}{\boldsymbol{p}}
144-
\newcommand{\bfq}{\boldsymbol{q}}
145-
\newcommand{\bfx}{\boldsymbol{x}}
146-
\newcommand{\bfu}{\boldsymbol{u}}
147-
\newcommand{\bfv}{\boldsymbol{v}}
148-
\newcommand{\bfA}{\boldsymbol{A}}
149-
\newcommand{\bfB}{\boldsymbol{B}}
150-
\newcommand{\bfC}{\boldsymbol{C}}
151-
\newcommand{\bfM}{\boldsymbol{M}}
152-
\newcommand{\bfJ}{\boldsymbol{J}}
153-
\newcommand{\bfR}{\boldsymbol{R}}
154-
\newcommand{\bfT}{\boldsymbol{T}}
155-
\newcommand{\bfomega}{\boldsymbol{\omega}}
156-
\newcommand{\bftau}{\boldsymbol{\tau}}
157-
$$
158-

contents/bogo_sort/bogo_sort.md

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ In code, it looks something like this:
3636
{% sample lang="rs" %}
3737
[import:16-20, lang:"rust"](code/rust/bogosort.rs)
3838
{% sample lang="swift" %}
39-
[import:32-39, lang:"swift"](code/swift/bogosort.swift)
39+
[import:25-31, lang:"swift"](code/swift/bogosort.swift)
4040
{% endmethod %}
4141

4242
That's it.
@@ -79,22 +79,3 @@ Program.cs
7979
<script>
8080
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
8181
</script>
82-
$$
83-
\newcommand{\d}{\mathrm{d}}
84-
\newcommand{\bff}{\boldsymbol{f}}
85-
\newcommand{\bfg}{\boldsymbol{g}}
86-
\newcommand{\bfp}{\boldsymbol{p}}
87-
\newcommand{\bfq}{\boldsymbol{q}}
88-
\newcommand{\bfx}{\boldsymbol{x}}
89-
\newcommand{\bfu}{\boldsymbol{u}}
90-
\newcommand{\bfv}{\boldsymbol{v}}
91-
\newcommand{\bfA}{\boldsymbol{A}}
92-
\newcommand{\bfB}{\boldsymbol{B}}
93-
\newcommand{\bfC}{\boldsymbol{C}}
94-
\newcommand{\bfM}{\boldsymbol{M}}
95-
\newcommand{\bfJ}{\boldsymbol{J}}
96-
\newcommand{\bfR}{\boldsymbol{R}}
97-
\newcommand{\bfT}{\boldsymbol{T}}
98-
\newcommand{\bfomega}{\boldsymbol{\omega}}
99-
\newcommand{\bftau}{\boldsymbol{\tau}}
100-
$$

contents/bogo_sort/code/swift/bogosort.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,32 @@
11
import Foundation
22

3-
43
func isSorted(inputArray: [Int]) -> Bool {
5-
64
for i in 0..<inputArray.count-1 {
75
if inputArray[i] > inputArray[i+1] {
86
return false
97
}
108
}
11-
9+
1210
return true
1311
}
1412

15-
16-
1713
func shuffle(inputArray: inout [Int]) -> [Int] {
18-
1914
var shuffledArray = [Int]()
2015

2116
for _ in 0..<inputArray.count {
2217
let rand = Int(arc4random_uniform(UInt32(inputArray.count)))
2318
shuffledArray.append(inputArray[rand])
2419
inputArray.remove(at: rand)
2520
}
26-
21+
2722
return shuffledArray
2823
}
2924

30-
31-
3225
func bogoSort(sortArray: inout [Int]) -> [Int] {
33-
3426
while(!isSorted(inputArray: sortArray)) {
3527
sortArray = shuffle(inputArray: &sortArray)
3628
}
37-
29+
3830
return sortArray
3931
}
4032

contents/bubble_sort/bubble_sort.md

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
2525
{% sample lang="hs" %}
2626
[import, lang:"haskell"](code/haskell/bubbleSort.hs)
2727
{% sample lang="cpp" %}
28-
[import:33-56, lang:"c_cpp"](code/c++/bubblesort.cpp)
28+
[import:13-23, lang:"c_cpp"](code/c++/bubblesort.cpp)
2929
{% sample lang="rs" %}
3030
[import:6-16, lang:"rust"](code/rust/bubble_sort.rs)
3131
{% sample lang="d" %}
@@ -35,9 +35,15 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
3535
{% sample lang="racket" %}
3636
[import:6-19, lang:"racket"](code/racket/bubbleSort.rkt)
3737
{% sample lang="swift" %}
38-
[import:1-12, lang:"swift"](code/swift/bubblesort.swift)
38+
[import:1-13, lang:"swift"](code/swift/bubblesort.swift)
3939
{% sample lang="ti83b" %}
4040
[import:2-13, lang:"ti-83_basic"](code/ti83basic/BUBLSORT.txt)
41+
{% sample lang="ruby" %}
42+
[import:3-13, lang:"ruby"](code/ruby/bubble.rb)
43+
{% sample lang="crystal" %}
44+
[import:1-11, lang:"crystal"](code/crystal/bubble.cr)
45+
{% sample lang="php" %}
46+
[import:3-15, lang:"php"](code/php/bubble_sort.php)
4147
{% endmethod %}
4248

4349
... And that's it for the simplest bubble sort method.
@@ -81,27 +87,14 @@ Program.cs
8187
[import, lang:"swift"](code/swift/bubblesort.swift)
8288
{% sample lang="ti83b" %}
8389
[import, lang:"ti-83_basic"](code/ti83basic/BUBLSORT.txt)
90+
{% sample lang="ruby" %}
91+
[import, lang:ruby"](code/ruby/bubble.rb)
92+
{% sample lang="crystal" %}
93+
[import, lang:"crystal"](code/crystal/bubble.cr)
94+
{% sample lang="php" %}
95+
[import, lang:"php"](code/php/bubble_sort.php)
8496
{% endmethod %}
8597

8698
<script>
8799
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
88100
</script>
89-
$$
90-
\newcommand{\d}{\mathrm{d}}
91-
\newcommand{\bff}{\boldsymbol{f}}
92-
\newcommand{\bfg}{\boldsymbol{g}}
93-
\newcommand{\bfp}{\boldsymbol{p}}
94-
\newcommand{\bfq}{\boldsymbol{q}}
95-
\newcommand{\bfx}{\boldsymbol{x}}
96-
\newcommand{\bfu}{\boldsymbol{u}}
97-
\newcommand{\bfv}{\boldsymbol{v}}
98-
\newcommand{\bfA}{\boldsymbol{A}}
99-
\newcommand{\bfB}{\boldsymbol{B}}
100-
\newcommand{\bfC}{\boldsymbol{C}}
101-
\newcommand{\bfM}{\boldsymbol{M}}
102-
\newcommand{\bfJ}{\boldsymbol{J}}
103-
\newcommand{\bfR}{\boldsymbol{R}}
104-
\newcommand{\bfT}{\boldsymbol{T}}
105-
\newcommand{\bfomega}{\boldsymbol{\omega}}
106-
\newcommand{\bftau}{\boldsymbol{\tau}}
107-
$$

contents/bubble_sort/code/c++/bubblesort.cpp

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,70 +2,34 @@
22
#include <cstddef>
33
#include <iostream>
44
#include <iterator>
5-
#include <random>
6-
7-
using std::begin;
8-
using std::end;
9-
10-
template <class Rng>
11-
std::vector<float> generate_input(std::size_t size, Rng& rng) {
12-
auto dist = std::uniform_real_distribution<>(0.0, 1.0);
13-
14-
auto ret = std::vector<float>();
15-
std::generate_n(std::back_inserter(ret), size,
16-
[&rng, &dist] { return dist(rng); });
17-
18-
return ret;
19-
}
205

216
template <class Iter>
22-
void print_range(std::ostream& os, Iter const first, Iter const last) {
23-
os << '{';
24-
25-
if (first != last) {
26-
os << *first;
27-
std::for_each(first + 1, last, [&os] (double d) { os << ", " << d; });
28-
}
29-
30-
os << "}\n";
7+
void print_range(Iter first, Iter last) {
8+
for (auto it = first; it != last; ++it)
9+
std::cout << *it << " ";
10+
std::cout << std::endl;
3111
}
3212

3313
template <class Iter>
34-
void bubble_sort(Iter const first, Iter const last) {
35-
if (first == last) {
36-
// the empty range is vacuously sorted
37-
return;
38-
}
39-
40-
for (;;) {
41-
bool is_sorted = true;
42-
43-
for (auto it = first; it + 1 != last; ++it) {
14+
void bubble_sort(Iter first, Iter last) {
15+
for (auto it1 = first; it1 != last; ++it1) {
16+
for (auto it2 = first; it2 + 1 != last; ++it2) {
4417
// these are unsorted! gotta swap 'em
45-
if (*(it + 1) < *it) {
46-
using std::swap;
47-
swap(*it, *(it + 1));
48-
is_sorted = false;
18+
if (*(it2 + 1) < *it2) {
19+
std::iter_swap(it2, it2 + 1);
4920
}
5021
}
51-
52-
if (is_sorted) {
53-
break;
54-
}
5522
}
5623
}
5724

5825
int main() {
59-
std::random_device random_device;
60-
auto rng = std::mt19937(random_device());
61-
62-
auto input = generate_input(10, rng);
26+
int input[] = {1, 45, 756, 4569, 56, 3, 8, 5, -10, -4};
6327

64-
std::cout << "before sorting:\n";
65-
print_range(std::cout, begin(input), end(input));
28+
std::cout << "Unsorted array:\n";
29+
print_range(std::begin(input), std::end(input));
6630

67-
bubble_sort(begin(input), end(input));
31+
bubble_sort(std::begin(input), std::end(input));
6832

69-
std::cout << "\nafter sorting:\n";
70-
print_range(std::cout, begin(input), end(input));
33+
std::cout << "\nSorted array:\n";
34+
print_range(std::begin(input), std::end(input));
7135
}

0 commit comments

Comments
 (0)