From 8d705fbd69bffea51caccf1dd0fc6b6f7b90d9ae Mon Sep 17 00:00:00 2001
From: Nicholas Tindle
Date: Mon, 16 Aug 2021 22:55:32 -0500
Subject: [PATCH 001/146] rename task to just build (#826)
---
.github/workflows/build.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 9c6e68b99..2d25ca4d3 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -2,7 +2,7 @@ name: build
on: pull_request
jobs:
- build-and-deploy:
+ build:
runs-on: ubuntu-latest
steps:
- name: Checkout
From c8da58e90231c821b0b48a651adc77005a96c325 Mon Sep 17 00:00:00 2001
From: James Schloss
Date: Wed, 18 Aug 2021 13:23:26 +0900
Subject: [PATCH 002/146] fixing order of function arguments (#827)
---
.../approximate_counting/code/julia/approximate_counting.jl | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/contents/approximate_counting/code/julia/approximate_counting.jl b/contents/approximate_counting/code/julia/approximate_counting.jl
index 9a10eae59..5e1fa86c3 100644
--- a/contents/approximate_counting/code/julia/approximate_counting.jl
+++ b/contents/approximate_counting/code/julia/approximate_counting.jl
@@ -52,10 +52,10 @@ end
@testset "Counting Tests, 100 trials" begin
println("testing 1,000, a = 30, 1% error")
- test_approximate_count(0.1, 100, 1000, 30)
+ test_approximate_count(100, 1000, 30, 0.1)
println("testing 12,345, a = 10, 1% error")
- test_approximate_count(0.1, 100, 12345, 10)
+ test_approximate_count(100, 12345, 10, 0.1)
# Note: with a lower a, we need more trials, so a higher % error here.
println("testing 222,222, a = 0.5, 10% error")
- test_approximate_count(0.1, 100, 222222, 0.5)
+ test_approximate_count(100, 222222, 0.5, 0.2)
end
From fb01675a12e567c6a92d6ab6a74c019e7d02dee1 Mon Sep 17 00:00:00 2001
From: James Schloss
Date: Wed, 18 Aug 2021 13:23:57 +0900
Subject: [PATCH 003/146] adding kotlin back to the chapter for the euclidean
algorithm (#825)
---
contents/euclidean_algorithm/euclidean_algorithm.md | 2 ++
1 file changed, 2 insertions(+)
diff --git a/contents/euclidean_algorithm/euclidean_algorithm.md b/contents/euclidean_algorithm/euclidean_algorithm.md
index 035e7ae81..82aa64a2a 100644
--- a/contents/euclidean_algorithm/euclidean_algorithm.md
+++ b/contents/euclidean_algorithm/euclidean_algorithm.md
@@ -210,6 +210,8 @@ Here's a video on the Euclidean algorithm:
[import, lang="c_cpp"](code/c++/euclidean.cpp)
{% sample lang="java" %}
[import, lang="java"](code/java/EuclideanAlgo.java)
+{% sample lang="kotlin" %}
+[import, lang="kotlin"](code/kotlin/Euclidean.kt)
{% sample lang="js" %}
[import, lang="javascript"](code/javascript/euclidean_example.js)
{% sample lang="lisp" %}
From 62f1c5ff16f5d8ef50691dab001f04e6a401183a Mon Sep 17 00:00:00 2001
From: Ken Power
Date: Wed, 18 Aug 2021 00:35:58 -0400
Subject: [PATCH 004/146] Comptus implementation in Scala (#808)
* Comptus implementation in Scala
* fixed filename in chapter
---
.../computus/code/scala/gauss_easter.scala | 58 +++++++++++++++++++
contents/computus/computus.md | 2 +
2 files changed, 60 insertions(+)
create mode 100644 contents/computus/code/scala/gauss_easter.scala
diff --git a/contents/computus/code/scala/gauss_easter.scala b/contents/computus/code/scala/gauss_easter.scala
new file mode 100644
index 000000000..01f5a4c30
--- /dev/null
+++ b/contents/computus/code/scala/gauss_easter.scala
@@ -0,0 +1,58 @@
+object GaussEaster {
+ def computus(year : Int, servois: Boolean = false): String = {
+
+ // Year's position on the 19 year metonic cycle
+ val a = year % 19
+
+ // Century index
+ val k = (year / 100).toInt
+
+ // Shift of metonic cycle, add a day offset every 300 years
+ val p = ((13 + 8 * k) / 25).toInt
+
+ // Correction for non-observed leap days
+ val q = (k / 4).toInt
+
+ // Correction to starting point of calculation each century
+ val M = (15 - p + k - q) % 30
+
+ // Number of days from March 21st until the full moon
+ val d = (19 * a + M) % 30
+
+ // Returning if user wants value for Servois' table
+ if (servois)
+ return s"${(21 + d) % 31}"
+
+ // Finding the next Sunday
+ // Century-based offset in weekly calculation
+ val N = (4 + k - q) % 7
+
+ // Correction for leap days
+ val b = year % 4
+ val c = year % 7
+
+ // Days from d to next Sunday
+ var e = (2 * b + 4 * c + 6 * d + N) % 7
+
+ // Historical corrections for April 26 and 25
+ if ((d == 29 && e == 6) || (d == 28 && e == 6 && a > 10)) {
+ e = -1
+ }
+
+ // Determination of the correct month for Easter
+ if (22 + d + e > 31)
+ s"April ${d + e - 9}"
+ else
+ s"March ${22 + d + e}"
+ }
+
+ def main(args: Array[String]): Unit = {
+ println("The following are the dates of the Paschal full moon (using " +
+ "Servois notation) and the date of Easter for 2020-2030 AD:\n" +
+ "Year\tServois number\tEaster\n")
+
+ for( year <- 2020 to 2030){
+ println(s"$year \t\t ${computus(year, true)} \t${computus(year)}")
+ }
+ }
+}
\ No newline at end of file
diff --git a/contents/computus/computus.md b/contents/computus/computus.md
index 6be87f2f6..31071d5f1 100644
--- a/contents/computus/computus.md
+++ b/contents/computus/computus.md
@@ -320,6 +320,8 @@ For now, we have the code outputting a tuple of $$d$$ and $$e$$, so users can us
[import, lang:"lisp"](code/clisp/gauss-easter.lisp)
{% sample lang="nim" %}
[import, lang:"nim"](code/nim/gauss_easter.nim)
+{% sample lang="scala" %}
+[import, lang:"scala"](code/scala/gauss_easter.scala)
{% endmethod %}
From 77a8f06ac71ffd060a5526fecdf49b5a8bd6a75e Mon Sep 17 00:00:00 2001
From: stormofice <58337328+stormofice@users.noreply.github.com>
Date: Mon, 23 Aug 2021 06:16:00 +0200
Subject: [PATCH 005/146] Fix typo in barnsley/julia (#829)
---
contents/barnsley/code/julia/barnsley.jl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contents/barnsley/code/julia/barnsley.jl b/contents/barnsley/code/julia/barnsley.jl
index 87aeb2bc3..779d7a13a 100644
--- a/contents/barnsley/code/julia/barnsley.jl
+++ b/contents/barnsley/code/julia/barnsley.jl
@@ -22,7 +22,7 @@ end
# This is a general function to simulate a chaos game
# n is the number of iterations
-# initial_location is the the starting point of the chaos game
+# initial_location is the starting point of the chaos game
# hutchinson_op is the set of functions to iterate through
# probabilities is the set of probabilities corresponding to the likelihood
# of choosing their corresponding function in hutchinson_op
From 2797d85ae0348395f403cc2f3ec13e5bc1bb3d90 Mon Sep 17 00:00:00 2001
From: Progyan Bhattacharya
Date: Mon, 23 Aug 2021 10:00:28 +0530
Subject: [PATCH 006/146] feat(ts): stack and queue implementation (#775)
---
.../code/typescript/queue.ts | 52 +++++++++++++++++++
.../code/typescript/stack.ts | 52 +++++++++++++++++++
2 files changed, 104 insertions(+)
create mode 100644 contents/stacks_and_queues/code/typescript/queue.ts
create mode 100644 contents/stacks_and_queues/code/typescript/stack.ts
diff --git a/contents/stacks_and_queues/code/typescript/queue.ts b/contents/stacks_and_queues/code/typescript/queue.ts
new file mode 100644
index 000000000..59d9c8321
--- /dev/null
+++ b/contents/stacks_and_queues/code/typescript/queue.ts
@@ -0,0 +1,52 @@
+interface IQueue {
+ /**
+ * `dequeue` removes first element from the queue and returns the same
+ */
+ dequeue(): T;
+ /**
+ * `enqueue` adds element to last of the queue and returns the size
+ */
+ enqueue(data: T): number;
+ /**
+ * `size` return size or length of the queue
+ */
+ size(): number;
+ /**
+ * `front` returns first element of the queue
+ */
+ front(): T;
+}
+
+class Queue implements IQueue {
+ private readonly list: Array = [];
+
+ public enqueue(data: T) {
+ return this.list.push(data);
+ }
+
+ public dequeue() {
+ return this.list.shift();
+ }
+
+ public size() {
+ return this.list.length;
+ }
+
+ public front() {
+ return this.list[0];
+ }
+}
+
+function exampleQueue() {
+ const numberQueue = new Queue();
+
+ numberQueue.enqueue(4);
+ numberQueue.enqueue(5);
+ numberQueue.enqueue(9);
+
+ console.log(numberQueue.dequeue());
+ console.log(numberQueue.size());
+ console.log(numberQueue.front());
+}
+
+exampleQueue();
diff --git a/contents/stacks_and_queues/code/typescript/stack.ts b/contents/stacks_and_queues/code/typescript/stack.ts
new file mode 100644
index 000000000..58b38ac40
--- /dev/null
+++ b/contents/stacks_and_queues/code/typescript/stack.ts
@@ -0,0 +1,52 @@
+interface IStack {
+ /**
+ * `pop` removes last element from the stack and returns the same
+ */
+ pop(): T;
+ /**
+ * `push` adds element to last of the stack and returns the size
+ */
+ push(data: T): number;
+ /**
+ * `size` return size or length of the stack
+ */
+ size(): number;
+ /**
+ * `top` returns last element of the stack
+ */
+ top(): T;
+}
+
+class Stack implements IStack {
+ private readonly list: Array = [];
+
+ public push(data: T) {
+ return this.list.push(data);
+ }
+
+ public pop() {
+ return this.list.pop();
+ }
+
+ public size() {
+ return this.list.length;
+ }
+
+ public top() {
+ return this.list[this.list.length - 1];
+ }
+}
+
+function exampleStack() {
+ const numberStack = new Stack();
+
+ numberStack.push(4);
+ numberStack.push(5);
+ numberStack.push(9);
+
+ console.log(numberStack.pop());
+ console.log(numberStack.size());
+ console.log(numberStack.top());
+}
+
+exampleStack();
From 841cb1132cd528950e46039a69be26cfbc7d5f59 Mon Sep 17 00:00:00 2001
From: Ridham Zalawadia <33592738+Ridham177@users.noreply.github.com>
Date: Mon, 23 Aug 2021 20:38:02 -0700
Subject: [PATCH 007/146] Convolutions of Images 2d Python implementation
(#819)
* Added python code for convolutions 2d. Modified 2d.md file to include added python code.
* Updated list comprehension code to numpy code. Changed if statements to not use escape character
* fixed minor errors
* solved minor errors
* Changed circle size. Removed test values for x and y
* Update contents/convolutions/2d/2d.md
Co-authored-by: James Schloss
* Update contents/convolutions/2d/2d.md
Co-authored-by: James Schloss
* added name to contributors.md
* resolved conflict
* removed name from contributors.md. will add next commit
* added name to contributors.md
Co-authored-by: James Schloss
---
CONTRIBUTORS.md | 1 +
contents/convolutions/2d/2d.md | 8 ++
.../code/python/2d_convolution.py | 122 ++++++++++++++++++
3 files changed, 131 insertions(+)
create mode 100644 contents/convolutions/code/python/2d_convolution.py
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 29d9e8e09..d594ad218 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -56,3 +56,4 @@ This file lists everyone, who contributed to this repo and wanted to show up her
- Ishaan Verma
- Delphi1024
- ntindle
+- Ridham177
diff --git a/contents/convolutions/2d/2d.md b/contents/convolutions/2d/2d.md
index d026c8a52..7fc21aeb6 100644
--- a/contents/convolutions/2d/2d.md
+++ b/contents/convolutions/2d/2d.md
@@ -21,6 +21,8 @@ In code, a two-dimensional convolution might look like this:
{% method %}
{% sample lang="jl" %}
[import:4-28, lang:"julia"](../code/julia/2d_convolution.jl)
+{% sample lang="py" %}
+[import:5-19, lang:"python"](../code/python/2d_convolution.py)
{% endmethod %}
This is very similar to what we have shown in previous sections; however, it essentially requires four iterable dimensions because we need to iterate through each axis of the output domain *and* the filter.
@@ -48,6 +50,8 @@ At this stage, it is important to write some code, so we will generate a simple
{% method %}
{% sample lang="jl" %}
[import:30-47, lang:"julia"](../code/julia/2d_convolution.jl)
+{% sample lang="py" %}
+[import:21-33, lang:"python"](../code/python/2d_convolution.py)
{% endmethod %}
Though it is entirely possible to create a Gaussian kernel whose standard deviation is independent on the kernel size, we have decided to enforce a relation between the two in this chapter.
@@ -135,6 +139,8 @@ In code, the Sobel operator involves first finding the operators in $$x$$ and $$
{% method %}
{% sample lang="jl" %}
[import:49-63, lang:"julia"](../code/julia/2d_convolution.jl)
+{% sample lang="py" %}
+[import:36-52, lang:"python"](../code/python/2d_convolution.py)
{% endmethod %}
With that, I believe we are at a good place to stop discussions on two-dimensional convolutions.
@@ -148,6 +154,8 @@ We have also added code to create the Gaussian kernel and Sobel operator and app
{% method %}
{% sample lang="jl" %}
[import, lang:"julia"](../code/julia/2d_convolution.jl)
+{% sample lang="py" %}
+[import, lang:"python"](../code/python/2d_convolution.py)
{% endmethod %}
@@ -54,6 +63,11 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+##### Images/Graphics
+
+- The image "[Cyclic](../res/cyclic.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
+
+
##### Text
The text of this chapter was written by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
From 46bf5a378ae875c56369cdaa8da7b93c4f0e7ce4 Mon Sep 17 00:00:00 2001
From: Ayman Lafaz
Date: Sun, 10 Oct 2021 15:15:43 +0100
Subject: [PATCH 040/146] added convolutional theorem implementation in python
(#869)
* added convolutional theorem implementation in python
* fixed chapter linking
* added comments to the code
* changed random distribution to sawtooth
* corrected previous commit
* fixed comments
Co-authored-by: James Schloss
---
.../code/python/convolutional_theorem.py | 19 +++++++++++++++++++
.../convolutional_theorem.md | 3 ++-
2 files changed, 21 insertions(+), 1 deletion(-)
create mode 100644 contents/convolutions/convolutional_theorem/code/python/convolutional_theorem.py
diff --git a/contents/convolutions/convolutional_theorem/code/python/convolutional_theorem.py b/contents/convolutions/convolutional_theorem/code/python/convolutional_theorem.py
new file mode 100644
index 000000000..f64f44a1d
--- /dev/null
+++ b/contents/convolutions/convolutional_theorem/code/python/convolutional_theorem.py
@@ -0,0 +1,19 @@
+from scipy.fft import fft, ifft
+import numpy as np
+
+# using the convolutional theorem
+def convolve_fft(signal1, signal2):
+ return ifft(np.multiply(fft(signal1),fft(signal2)))
+
+# Sawtooth functions
+x = [float(i)/200 for i in range(1,101)]
+y = [float(i)/200 for i in range(1,101)]
+
+x /= np.linalg.norm(x)
+y /= np.linalg.norm(y)
+
+# Convolving the two signals
+fft_output = convolve_fft(x, y)
+
+np.savetxt("fft.dat", np.real(fft_output))
+
diff --git a/contents/convolutions/convolutional_theorem/convolutional_theorem.md b/contents/convolutions/convolutional_theorem/convolutional_theorem.md
index 7aa5c3fdf..1034f2018 100644
--- a/contents/convolutions/convolutional_theorem/convolutional_theorem.md
+++ b/contents/convolutions/convolutional_theorem/convolutional_theorem.md
@@ -44,6 +44,8 @@ For this example code, we will be using two sawtooth functions as we did in the
{% method %}
{% sample lang="jl" %}
[import, lang:"julia"](code/julia/convolutional_theorem.jl)
+{% sample lang="py" %}
+[import, lang:"python"](code/python/convolutional_theorem.py)
{% endmethod %}
This should produce the following output:
@@ -52,7 +54,6 @@ This should produce the following output:
@@ -64,7 +64,7 @@ Because of this, the most straightforward way to traverse the tree might be recu
{% sample lang="js" %}
[import:12-19, lang:"javascript"](code/javascript/tree.js)
{% sample lang="py" %}
-[import:18-23, lang:"python"](code/python/Tree_example.py)
+[import:17-22, lang:"python"](code/python/tree_traversal.py)
{% sample lang="scratch" %}
@@ -72,11 +72,11 @@ Because of this, the most straightforward way to traverse the tree might be recu
{% sample lang="rs" %}
[import:9-15 lang:"rust"](code/rust/tree.rs)
{% sample lang="hs" %}
-[import:6-7, lang:"haskell"](code/haskell/TreeTraversal.hs)
+[import:7-8, lang:"haskell"](code/haskell/TreeTraversal.hs)
{% sample lang="swift" %}
[import:24-30, lang:"swift"](code/swift/tree.swift)
{% sample lang="php" %}
-[import:41-49, lang:"php"](code/php/tree_traversal.php)
+[import:41-47, lang:"php"](code/php/tree_traversal.php)
{% sample lang="crystal" %}
[import:7-10, lang:"crystal"](code/crystal/tree-traversal.cr)
{% sample lang="st" %}
@@ -120,7 +120,7 @@ Now, in this case the first element searched through is still the root of the tr
{% sample lang="js" %}
[import:21-28, lang:"javascript"](code/javascript/tree.js)
{% sample lang="py" %}
-[import:26-31, lang:"python"](code/python/Tree_example.py)
+[import:25-30, lang:"python"](code/python/tree_traversal.py)
{% sample lang="scratch" %}
@@ -128,11 +128,11 @@ Now, in this case the first element searched through is still the root of the tr
{% sample lang="rs" %}
[import:17-24, lang:"rust"](code/rust/tree.rs)
{% sample lang="hs" %}
-[import:9-10, lang:"haskell"](code/haskell/TreeTraversal.hs)
+[import:10-11, lang:"haskell"](code/haskell/TreeTraversal.hs)
{% sample lang="swift" %}
[import:32-38, lang:"swift"](code/swift/tree.swift)
{% sample lang="php" %}
-[import:51-57, lang:"php"](code/php/tree_traversal.php)
+[import:49-55, lang:"php"](code/php/tree_traversal.php)
{% sample lang="crystal" %}
[import:12-15, lang:"crystal"](code/crystal/tree-traversal.cr)
{% sample lang="st" %}
@@ -148,7 +148,7 @@ Now, in this case the first element searched through is still the root of the tr
{% sample lang="m" %}
[import:47-62, lang:"matlab"](code/matlab/tree.m)
{% sample lang="coco" %}
-[import:11-15, lang:="coconut"](codo/coconut/tree_traversal.coco)
+[import:11-15, lang:="coconut"](code/coconut/tree_traversal.coco)
{% endmethod %}
@@ -171,7 +171,7 @@ In this case, the first node visited is at the bottom of the tree and moves up t
{% sample lang="js" %}
[import:30-51, lang:"javascript"](code/javascript/tree.js)
{% sample lang="py" %}
-[import:34-46, lang:"python"](code/python/Tree_example.py)
+[import:34-45, lang:"python"](code/python/tree_traversal.py)
{% sample lang="scratch" %}
@@ -179,11 +179,11 @@ In this case, the first node visited is at the bottom of the tree and moves up t
{% sample lang="rs" %}
[import:25-40, lang:"rust"](code/rust/tree.rs)
{% sample lang="hs" %}
-[import:12-16, lang:"haskell"](code/haskell/TreeTraversal.hs)
+[import:13-17, lang:"haskell"](code/haskell/TreeTraversal.hs)
{% sample lang="swift" %}
[import:40-53, lang:"swift"](code/swift/tree.swift)
{% sample lang="php" %}
-[import:59-78, lang:"php"](code/php/tree_traversal.php)
+[import:57-76, lang:"php"](code/php/tree_traversal.php)
{% sample lang="crystal" %}
[import:17-31, lang:"crystal"](code/crystal/tree-traversal.cr)
{% sample lang="st" %}
@@ -231,7 +231,7 @@ In code, it looks like this:
{% sample lang="js" %}
[import:53-60, lang:"javascript"](code/javascript/tree.js)
{% sample lang="py" %}
-[import:49-60, lang:"python"](code/python/Tree_example.py)
+[import:48-59, lang:"python"](code/python/tree_traversal.py)
{% sample lang="scratch" %}
@@ -239,11 +239,11 @@ In code, it looks like this:
{% sample lang="rs" %}
[import:41-48, lang:"rust"](code/rust/tree.rs)
{% sample lang="hs" %}
-[import:18-22, lang:"haskell"](code/haskell/TreeTraversal.hs)
+[import:19-23, lang:"haskell"](code/haskell/TreeTraversal.hs)
{% sample lang="swift" %}
[import:55-67, lang:"swift"](code/swift/tree.swift)
{% sample lang="php" %}
-[import:80-91, lang:"php"](code/php/tree_traversal.php)
+[import:78-89, lang:"php"](code/php/tree_traversal.php)
{% sample lang="crystal" %}
[import:33-41, lang:"crystal"](code/crystal/tree-traversal.cr)
{% sample lang="st" %}
@@ -284,7 +284,7 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
{% sample lang="js" %}
[import:62-69, lang:"javascript"](code/javascript/tree.js)
{% sample lang="py" %}
-[import:63-75, lang:"python"](code/python/Tree_example.py)
+[import:62-72, lang:"python"](code/python/tree_traversal.py)
{% sample lang="scratch" %}
@@ -292,11 +292,11 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
{% sample lang="rs" %}
[import:50-58, lang:"rust"](code/rust/tree.rs)
{% sample lang="hs" %}
-[import:24-28, lang:"haskell"](code/haskell/TreeTraversal.hs)
+[import:25-29, lang:"haskell"](code/haskell/TreeTraversal.hs)
{% sample lang="swift" %}
[import:69-81, lang:"swift"](code/swift/tree.swift)
{% sample lang="php" %}
-[import:93-104, lang:"php"](code/php/tree_traversal.php)
+[import:91-102, lang:"php"](code/php/tree_traversal.php)
{% sample lang="crystal" %}
[import:43-51, lang:"crystal"](code/crystal/tree-traversal.cr)
{% sample lang="st" %}
@@ -345,7 +345,7 @@ Here is a video describing tree traversal:
{% sample lang="js" %}
[import, lang:"javascript"](code/javascript/tree.js)
{% sample lang="py" %}
-[import, lang:"python"](code/python/Tree_example.py)
+[import, lang:"python"](code/python/tree_traversal.py)
{% sample lang="scratch" %}
The code snippets were taken from this [Scratch project](https://scratch.mit.edu/projects/174017753/)
From 83df0b9dbb32f5809b8aaf2c595455d62a556d39 Mon Sep 17 00:00:00 2001
From: James Schloss
Date: Tue, 26 Oct 2021 17:07:58 +0200
Subject: [PATCH 060/146] Partial removal (#905)
* removing partial implementations
* removing languages completely
---
contents/cooley_tukey/cooley_tukey.md | 6 ---
.../verlet_integration/verlet_integration.md | 40 -------------------
2 files changed, 46 deletions(-)
diff --git a/contents/cooley_tukey/cooley_tukey.md b/contents/cooley_tukey/cooley_tukey.md
index d67d4dbd2..67309b5d2 100644
--- a/contents/cooley_tukey/cooley_tukey.md
+++ b/contents/cooley_tukey/cooley_tukey.md
@@ -81,8 +81,6 @@ For some reason, though, putting code to this transformation really helped me fi
[import:7-13, lang:"haskell"](code/haskell/fft.hs)
{% sample lang="py" %}
[import:6-12, lang:"python"](code/python/fft.py)
-{% sample lang="scratch" %}
-[import:4-13, lang:"julia"](code/julia/fft.jl)
{% sample lang="asm-x64" %}
[import:15-74, lang:"asm-x64"](code/asm-x64/fft.s)
{% sample lang="js" %}
@@ -136,8 +134,6 @@ In the end, the code looks like:
[import:15-28, lang:"haskell"](code/haskell/fft.hs)
{% sample lang="py" %}
[import:15-26, lang:"python"](code/python/fft.py)
-{% sample lang="scratch" %}
-[import:16-32, lang:"julia"](code/julia/fft.jl)
{% sample lang="asm-x64" %}
[import:76-165, lang:"asm-x64"](code/asm-x64/fft.s)
{% sample lang="js" %}
@@ -251,8 +247,6 @@ Note: I implemented this in Julia because the code seems more straightforward in
[import, lang:"haskell"](code/haskell/fft.hs)
{% sample lang="py" %}
[import, lang:"python"](code/python/fft.py)
-{% sample lang="scratch" %}
-Some rather impressive scratch code was submitted by Jie and can be found here: https://scratch.mit.edu/projects/37759604/#editor
{% sample lang="asm-x64" %}
[import, lang:"asm-x64"](code/asm-x64/fft.s)
{% sample lang="js" %}
diff --git a/contents/verlet_integration/verlet_integration.md b/contents/verlet_integration/verlet_integration.md
index 402a7ba1b..08fe4a4b3 100644
--- a/contents/verlet_integration/verlet_integration.md
+++ b/contents/verlet_integration/verlet_integration.md
@@ -42,15 +42,6 @@ Here is what it looks like in code:
[import:1-10, lang:"python"](code/python/verlet.py)
{% sample lang="hs" %}
[import:14-21, lang:"haskell"](code/haskell/verlet.hs)
-{% sample lang="scratch" %}
-Unfortunately, this has not yet been implemented in scratch, so here's Julia code:
-[import:1-13, lang:"julia"](code/julia/verlet.jl)
-{% sample lang="m" %}
-Unfortunately, this has not yet been implemented in matlab, so here's Julia code:
-[import:1-13, lang:"julia"](code/julia/verlet.jl)
-{% sample lang="LabVIEW" %}
-Unfortunately, this has not yet been implemented in LabVIEW, so here's Julia code:
-[import:1-13, lang:"julia"](code/julia/verlet.jl)
{% sample lang="js" %}
[import:1-14, lang:"javascript"](code/javascript/verlet.js)
{% sample lang="rs" %}
@@ -100,15 +91,6 @@ However, the error for this is $$\mathcal{O}(\Delta t)$$, which is quite poor, b
[import:12-23, lang:"python"](code/python/verlet.py)
{% sample lang="hs" %}
[import:23-28, lang:"haskell"](code/haskell/verlet.hs)
-{% sample lang="scratch" %}
-Unfortunately, this has not yet been implemented in scratch, so here's Julia code:
-[import:15-31, lang:"julia"](code/julia/verlet.jl)
-{% sample lang="m" %}
-Unfortunately, this has not yet been implemented in matlab, so here's Julia code:
-[import:15-31, lang:"julia"](code/julia/verlet.jl)
-{% sample lang="LabVIEW" %}
-Unfortunately, this has not yet been implemented in LabVIEW, so here's Julia code:
-[import:15-31, lang:"julia"](code/julia/verlet.jl)
{% sample lang="js" %}
[import:16-32, lang:"javascript"](code/javascript/verlet.js)
{% sample lang="rs" %}
@@ -172,15 +154,6 @@ Here is the velocity Verlet method in code:
[import:25-34, lang:"python"](code/python/verlet.py)
{% sample lang="hs" %}
[import:30-35, lang:"haskell"](code/haskell/verlet.hs)
-{% sample lang="scratch" %}
-Unfortunately, this has not yet been implemented in scratch, so here's Julia code:
-[import:33-45, lang:"julia"](code/julia/verlet.jl)
-{% sample lang="m" %}
-Unfortunately, this has not yet been implemented in matlab, so here's Julia code:
-[import:33-45, lang:"julia"](code/julia/verlet.jl)
-{% sample lang="LabVIEW" %}
-Unfortunately, this has not yet been implemented in LabVIEW, so here's Julia code:
-[import:33-45, lang:"julia"](code/julia/verlet.jl)
{% sample lang="js" %}
[import:34-45, lang:"javascript"](code/javascript/verlet.js)
{% sample lang="rs" %}
@@ -230,19 +203,6 @@ Both of these methods work simply by iterating timestep-by-timestep and can be w
[import, lang:"python"](code/python/verlet.py)
{% sample lang="hs" %}
[import, lang:"haskell"](code/haskell/verlet.hs)
-{% sample lang="scratch" %}
-Submitted by Jie
-
-
-
-Link: [https://scratch.mit.edu/projects/173039394/](https://scratch.mit.edu/projects/173039394/)
-{% sample lang="m" %}
-[import, lang:"matlab"](code/matlab/verlet.m)
-{% sample lang="LabVIEW" %}
-Submitted by P. Mekhail
-
-
-
{% sample lang="js" %}
[import, lang:"javascript"](code/javascript/verlet.js)
{% sample lang="rs" %}
From cfcfccccc95484aa19d76397f6788e3f7c7fca9a Mon Sep 17 00:00:00 2001
From: Sammy Plat
Date: Tue, 26 Oct 2021 17:45:54 +0200
Subject: [PATCH 061/146] Added SCons compilation instructions (#885)
* Added C compilation to SCons (not all work, though)
* First fully functional version of the build system for C code
* Simplified SConstruct file
* Simplified SConscript files
SConscript files are now mostly universal for C programs.
Additionally, the build hierarchy is now flattened (executables under the language folder)
* fixing chapter to use split-op code (#888)
Removed the quantum_systems SConscript
* modified Dockerfile for ntindle
* Changed my name in CONTRIBUTORS.md
* apparently forgot an algorithm
Co-authored-by: James Schloss
---
.devcontainer/Dockerfile | 5 +++--
.gitignore | 7 +++++++
CONTRIBUTORS.md | 2 +-
SConscript | 10 ++++++++++
SConstruct | 20 +++++++++++++++++++
contents/IFS/code/c/SConscript | 6 ++++++
.../approximate_counting/code/c/SConscript | 6 ++++++
contents/barnsley/code/c/SConscript | 6 ++++++
contents/computus/code/c/SConscript | 6 ++++++
contents/cooley_tukey/code/c/SConscript | 6 ++++++
.../euclidean_algorithm/code/c/SConscript | 6 ++++++
contents/flood_fill/code/c/SConscript | 6 ++++++
.../forward_euler_method/code/c/SConscript | 6 ++++++
.../gaussian_elimination/code/c/SConscript | 6 ++++++
contents/graham_scan/code/c/SConscript | 6 ++++++
contents/huffman_encoding/code/c/SConscript | 6 ++++++
contents/jarvis_march/code/c/SConscript | 6 ++++++
.../monte_carlo_integration/code/c/SConscript | 6 ++++++
.../split-operator_method/code/c/SConscript | 6 ++++++
.../stable_marriage_problem/code/c/SConscript | 6 ++++++
contents/thomas_algorithm/code/c/SConscript | 6 ++++++
contents/tree_traversal/code/c/SConscript | 6 ++++++
contents/verlet_integration/code/c/SConscript | 6 ++++++
23 files changed, 149 insertions(+), 3 deletions(-)
create mode 100644 SConscript
create mode 100644 SConstruct
create mode 100644 contents/IFS/code/c/SConscript
create mode 100644 contents/approximate_counting/code/c/SConscript
create mode 100644 contents/barnsley/code/c/SConscript
create mode 100644 contents/computus/code/c/SConscript
create mode 100644 contents/cooley_tukey/code/c/SConscript
create mode 100644 contents/euclidean_algorithm/code/c/SConscript
create mode 100644 contents/flood_fill/code/c/SConscript
create mode 100644 contents/forward_euler_method/code/c/SConscript
create mode 100644 contents/gaussian_elimination/code/c/SConscript
create mode 100644 contents/graham_scan/code/c/SConscript
create mode 100644 contents/huffman_encoding/code/c/SConscript
create mode 100644 contents/jarvis_march/code/c/SConscript
create mode 100644 contents/monte_carlo_integration/code/c/SConscript
create mode 100644 contents/split-operator_method/code/c/SConscript
create mode 100644 contents/stable_marriage_problem/code/c/SConscript
create mode 100644 contents/thomas_algorithm/code/c/SConscript
create mode 100644 contents/tree_traversal/code/c/SConscript
create mode 100644 contents/verlet_integration/code/c/SConscript
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 18af4df12..aec4ab153 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -6,7 +6,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
- && apt-get -y install --no-install-recommends build-essential software-properties-common xz-utils g++ sbcl julia python3 python3-pip python3-dev ghc openjdk-11-jdk rustc libssl-dev gfortran libxml2-dev libyaml-dev libgmp-dev libz-dev libncurses5 gnuplot nodejs npm lua5.3 ocaml php ruby-full gnu-smalltalk scratch
+ && apt-get -y install --no-install-recommends build-essential software-properties-common xz-utils g++ sbcl julia python3 python3-pip python3-dev ghc openjdk-11-jdk rustc libssl-dev gfortran libxml2-dev libyaml-dev libgmp-dev libz-dev libncurses5 gnuplot nodejs npm lua5.3 ocaml php ruby-full gnu-smalltalk scratch libfftw3-dev
# Setup Crystal
RUN echo 'deb http://download.opensuse.org/repositories/devel:/languages:/crystal/xUbuntu_20.04/ /' | sudo tee /etc/apt/sources.list.d/devel:languages:crystal.list
@@ -98,6 +98,7 @@ ENV PATH=$PATH:~/swift/usr/bin
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends crystal dart nim powershell scala dotnet-sdk-5.0 r-base racket
-RUN pip install wheel matplotlib numpy coconut
+RUN pip install wheel matplotlib numpy coconut scons
RUN sudo sh -c 'npm install -g typescript'
+
diff --git a/.gitignore b/.gitignore
index db26e0ad0..231da8ea1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -517,3 +517,10 @@ vscode/
# aspell
*.bak
+
+# SCons intermidiate files
+.sconsign.dblite
+*.o
+
+# SCons build directory
+build/
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 9b2c1b460..82f3c173a 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -51,7 +51,7 @@ This file lists everyone, who contributed to this repo and wanted to show up her
- Vincent Zalzal
- Jonathan D B Van Schenck
- James Goytia
-- Amaras
+- Sammy Plat
- Jonathan Dönszelmann
- Ishaan Verma
- Delphi1024
diff --git a/SConscript b/SConscript
new file mode 100644
index 000000000..be18b33d3
--- /dev/null
+++ b/SConscript
@@ -0,0 +1,10 @@
+from pathlib import Path
+
+Import('*')
+
+for p in Path('contents').iterdir():
+ if (q := (p / 'code')).exists():
+ for path in q.iterdir():
+ if path.stem in languages:
+ env.SConscript(path / 'SConscript', exports='env',
+ must_exist=0)
diff --git a/SConstruct b/SConstruct
new file mode 100644
index 000000000..df000f732
--- /dev/null
+++ b/SConstruct
@@ -0,0 +1,20 @@
+"""
+SCons top-level build description (SConstruct) for the Arcane Algorithm Achive
+
+This provides Builder objects for each of the language implementations in the AAA; however, this work cannot be considered exhaustive until every language has been covered.
+
+Currently, the aim is to provide a way to compile or copy the implementation files to the build directory, as well as to provide ways to run them and capture their output.
+
+To run the compilation for all implmeentations in one language, e.g. Rust, run the command `scons build/c`, and the resulting executables will be available in the `cuild/c` directory, each in their respective algorithm directory, containing the executable."""
+
+from pathlib import Path
+
+env = Environment()
+
+# Add other languages here when you want to add language targets
+languages = ['c']
+
+env.C = env.Program
+
+SConscript('SConscript', exports='env languages')
+
diff --git a/contents/IFS/code/c/SConscript b/contents/IFS/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/IFS/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/approximate_counting/code/c/SConscript b/contents/approximate_counting/code/c/SConscript
new file mode 100644
index 000000000..34a951e7f
--- /dev/null
+++ b/contents/approximate_counting/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS='m')
diff --git a/contents/barnsley/code/c/SConscript b/contents/barnsley/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/barnsley/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/computus/code/c/SConscript b/contents/computus/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/computus/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/cooley_tukey/code/c/SConscript b/contents/cooley_tukey/code/c/SConscript
new file mode 100644
index 000000000..2cd13de37
--- /dev/null
+++ b/contents/cooley_tukey/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS=['m', 'fftw3'])
diff --git a/contents/euclidean_algorithm/code/c/SConscript b/contents/euclidean_algorithm/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/euclidean_algorithm/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/flood_fill/code/c/SConscript b/contents/flood_fill/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/flood_fill/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/forward_euler_method/code/c/SConscript b/contents/forward_euler_method/code/c/SConscript
new file mode 100644
index 000000000..34a951e7f
--- /dev/null
+++ b/contents/forward_euler_method/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS='m')
diff --git a/contents/gaussian_elimination/code/c/SConscript b/contents/gaussian_elimination/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/gaussian_elimination/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/graham_scan/code/c/SConscript b/contents/graham_scan/code/c/SConscript
new file mode 100644
index 000000000..34a951e7f
--- /dev/null
+++ b/contents/graham_scan/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS='m')
diff --git a/contents/huffman_encoding/code/c/SConscript b/contents/huffman_encoding/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/huffman_encoding/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/jarvis_march/code/c/SConscript b/contents/jarvis_march/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/jarvis_march/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/monte_carlo_integration/code/c/SConscript b/contents/monte_carlo_integration/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/monte_carlo_integration/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/split-operator_method/code/c/SConscript b/contents/split-operator_method/code/c/SConscript
new file mode 100644
index 000000000..2cd13de37
--- /dev/null
+++ b/contents/split-operator_method/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS=['m', 'fftw3'])
diff --git a/contents/stable_marriage_problem/code/c/SConscript b/contents/stable_marriage_problem/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/stable_marriage_problem/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/thomas_algorithm/code/c/SConscript b/contents/thomas_algorithm/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/thomas_algorithm/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/tree_traversal/code/c/SConscript b/contents/tree_traversal/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/tree_traversal/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/verlet_integration/code/c/SConscript b/contents/verlet_integration/code/c/SConscript
new file mode 100644
index 000000000..fd696f9ce
--- /dev/null
+++ b/contents/verlet_integration/code/c/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.C(f'#/build/c/{dirname}', Glob('*.c'))
From 4a81890603b389e5f281d8159e4cc441093859f8 Mon Sep 17 00:00:00 2001
From: Henrik Christensen
Date: Tue, 26 Oct 2021 18:19:52 +0200
Subject: [PATCH 062/146] c# tree traversal: fixed index out of range issue
(#894)
---
.../tree_traversal/code/csharp/Program.cs | 1 -
contents/tree_traversal/code/csharp/Tree.cs | 34 +++++++++++--------
contents/tree_traversal/tree_traversal.md | 12 +++----
3 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/contents/tree_traversal/code/csharp/Program.cs b/contents/tree_traversal/code/csharp/Program.cs
index 4308794dd..0fc35c547 100644
--- a/contents/tree_traversal/code/csharp/Program.cs
+++ b/contents/tree_traversal/code/csharp/Program.cs
@@ -1,4 +1,3 @@
-// submitted by Julian Schacher (jspp)
using System;
namespace TreeTraversal
diff --git a/contents/tree_traversal/code/csharp/Tree.cs b/contents/tree_traversal/code/csharp/Tree.cs
index f581008d7..28df47c91 100644
--- a/contents/tree_traversal/code/csharp/Tree.cs
+++ b/contents/tree_traversal/code/csharp/Tree.cs
@@ -1,4 +1,3 @@
-// submitted by Julian Schacher (jspp)
using System;
using System.Collections.Generic;
@@ -11,23 +10,23 @@ public class Tree
public Tree(int depthCount, int childrenCount)
{
- this.Id = depthCount;
+ Id = 1;
if (depthCount > 0)
{
for (int i = 0; i < childrenCount; i++)
- this._children.Add(new Tree(depthCount - 1, childrenCount));
+ _children.Add(new Tree(Id * 10 + i + 1, depthCount - 1, childrenCount));
}
}
private Tree(int id, int depthCount, int childrenCount)
{
- this.Id = id;
+ Id = id;
if (!(depthCount <= 1))
{
for (int i = 0; i < childrenCount; i++)
- this._children.Add(new Tree(this.Id * 10 + i + 1, depthCount - 1, childrenCount));
+ _children.Add(new Tree(Id * 10 + i + 1, depthCount - 1, childrenCount));
}
}
@@ -61,20 +60,25 @@ public void DFSRecursiveInorderBinary()
{
DFSRecursiveInorderBinary(this);
- // This assumes only 2 children
void DFSRecursiveInorderBinary(Tree tree)
{
- if (tree._children.Count > 2)
- throw new Exception("Not binary tree!");
-
- if (tree._children.Count > 0)
+ switch (tree._children.Count)
{
- DFSRecursiveInorderBinary(tree._children[0]);
- Console.Write(tree.Id + " ");
- DFSRecursiveInorderBinary(tree._children[1]);
+ case 2:
+ DFSRecursiveInorderBinary(tree._children[0]);
+ Console.Write(tree.Id + " ");
+ DFSRecursiveInorderBinary(tree._children[1]);
+ break;
+ case 1:
+ DFSRecursiveInorderBinary(tree._children[0]);
+ Console.Write(tree.Id + " ");
+ break;
+ case 0:
+ Console.Write(tree.Id + " ");
+ break;
+ default:
+ throw new Exception("Not binary tree!");
}
- else
- Console.Write(tree.Id + " ");
}
}
diff --git a/contents/tree_traversal/tree_traversal.md b/contents/tree_traversal/tree_traversal.md
index 94b9086a8..4b6c5b762 100644
--- a/contents/tree_traversal/tree_traversal.md
+++ b/contents/tree_traversal/tree_traversal.md
@@ -8,7 +8,7 @@ Trees are naturally recursive data structures, and because of this, we cannot ac
{% sample lang="cpp" %}
[import:12-15, lang:"cpp"](code/c++/tree_example.cpp)
{% sample lang="cs" %}
-[import:7-11, lang:"csharp"](code/csharp/Tree.cs)
+[import:6-10, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
[import:7-11, lang:"c"](code/c/tree_traversal.c)
{% sample lang="java" %}
@@ -56,7 +56,7 @@ Because of this, the most straightforward way to traverse the tree might be recu
{% sample lang="cpp" %}
[import:17-24, lang:"cpp"](code/c++/tree_example.cpp)
{% sample lang="cs" %}
-[import:34-45, lang:"csharp"](code/csharp/Tree.cs)
+[import:33-44, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
[import:37-45, lang:"c"](code/c/tree_traversal.c)
{% sample lang="java" %}
@@ -112,7 +112,7 @@ Now, in this case the first element searched through is still the root of the tr
{% sample lang="cpp" %}
[import:26-31, lang:"cpp"](code/c++/tree_example.cpp)
{% sample lang="cs" %}
-[import:47-58, lang:"csharp"](code/csharp/Tree.cs)
+[import:46-57, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
[import:47-53, lang:"c"](code/c/tree_traversal.c)
{% sample lang="java" %}
@@ -163,7 +163,7 @@ In this case, the first node visited is at the bottom of the tree and moves up t
{% sample lang="cpp" %}
[import:34-52 lang:"cpp"](code/c++/tree_example.cpp)
{% sample lang="cs" %}
-[import:60-79, lang:"csharp"](code/csharp/Tree.cs)
+[import:59-83, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
[import:55-73, lang:"c"](code/c/tree_traversal.c)
{% sample lang="java" %}
@@ -223,7 +223,7 @@ In code, it looks like this:
{% sample lang="cpp" %}
[import:55-70, lang:"cpp"](code/c++/tree_example.cpp)
{% sample lang="cs" %}
-[import:81-94, lang:"csharp"](code/csharp/Tree.cs)
+[import:85-98, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
[import:75-93, lang:"c"](code/c/tree_traversal.c)
{% sample lang="java" %}
@@ -276,7 +276,7 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
{% sample lang="cpp" %}
[import:73-86, lang:"cpp"](code/c++/tree_example.cpp)
{% sample lang="cs" %}
-[import:96-109, lang:"csharp"](code/csharp/Tree.cs)
+[import:100-113, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
[import:95-113, lang:"c"](code/c/tree_traversal.c)
{% sample lang="java" %}
From 91410d7ce05a6c0f673acbc72ca4c4bd08b392cb Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Tue, 2 Nov 2021 20:40:59 +0100
Subject: [PATCH 063/146] Add devcontainer setup for V lang
---
.devcontainer/Dockerfile | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 18af4df12..34299941f 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -91,8 +91,9 @@ ENV PATH=$PATH:~/swift/usr/bin
## https://github.com/elm/compiler/blob/master/installers/linux/README.md
# Setup V
-## https://github.com/vlang/v/blob/master/doc/docs.md
-
+RUN mkdir -p ~/vlang && wget https://github.com/vlang/v/releases/download/weekly.2021.44/v_linux.zip -O ~/vlang/vlang.zip && \
+ unzip ~/vlang/vlang.zip -d ~/vlang
+ENV PATH=$PATH:~/vlang/v
# Install the packages that needed extra help
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
From 3a75d02df481f5d7f973f06b4ffb514acb5b7880 Mon Sep 17 00:00:00 2001
From: Eric Berquist
Date: Wed, 3 Nov 2021 11:26:34 -0400
Subject: [PATCH 064/146] Change Racket lang include from lisp to racket (#884)
Co-authored-by: James Schloss
---
contents/euclidean_algorithm/euclidean_algorithm.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/contents/euclidean_algorithm/euclidean_algorithm.md b/contents/euclidean_algorithm/euclidean_algorithm.md
index 82aa64a2a..f44c3acb7 100644
--- a/contents/euclidean_algorithm/euclidean_algorithm.md
+++ b/contents/euclidean_algorithm/euclidean_algorithm.md
@@ -56,7 +56,7 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
{% sample lang="scala" %}
[import:3-8, lang="scala"](code/scala/euclidean.scala)
{% sample lang="racket" %}
-[import:3-14, lang="lisp"](code/racket/euclidean_algorithm.rkt)
+[import:3-14, lang="racket"](code/racket/euclidean_algorithm.rkt)
{% sample lang="ruby" %}
[import:8-19, lang="ruby"](code/ruby/euclidean.rb)
{% sample lang="st" %}
@@ -146,7 +146,7 @@ Modern implementations, though, often use the modulus operator (%) like so
{% sample lang="scala" %}
[import:10-14, lang="scala"](code/scala/euclidean.scala)
{% sample lang="racket" %}
-[import:16-24, lang="lisp"](code/racket/euclidean_algorithm.rkt)
+[import:16-24, lang="racket"](code/racket/euclidean_algorithm.rkt)
{% sample lang="ruby" %}
[import:1-6, lang="ruby"](code/ruby/euclidean.rb)
{% sample lang="st" %}
@@ -252,7 +252,7 @@ and modulo method:
{% sample lang="scala" %}
[import, lang="scala"](code/scala/euclidean.scala)
{% sample lang="racket" %}
-[import, lang="lisp"](code/racket/euclidean_algorithm.rkt)
+[import, lang="racket"](code/racket/euclidean_algorithm.rkt)
{% sample lang="ruby" %}
[import, lang="ruby"](code/ruby/euclidean.rb)
{% sample lang="st" %}
From 174c4975ae1a244424b08b547e290345dd22b409 Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Wed, 3 Nov 2021 19:46:39 +0100
Subject: [PATCH 065/146] Add devcontainer setup for VimL/Vim script (#912)
---
.devcontainer/Dockerfile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index eff8fd4da..ee273e5af 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -82,7 +82,8 @@ RUN mkdir -p ~/swift && wget https://swift.org/builds/swift-5.5-release/ubuntu20
ENV PATH=$PATH:~/swift/usr/bin
# Setup viml
-## ?
+# To run vim script commands use `/usr/bin/vim -c ":source %" `
+RUN export DEBIAN_FRONTEND=noninteractive && apt-get -y install --no-install-recommends vim
# Setup whitespace
## ?
From a3825b250d3eb0cab952af097b944361a777e0f4 Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Sun, 7 Nov 2021 15:49:28 +0100
Subject: [PATCH 066/146] Add devcontainer setup for Elm and fix Euler Elm
example (#911)
---
.devcontainer/Dockerfile | 4 +-
.../code/elm/elm-package.json | 20 -
.../forward_euler_method/code/elm/elm.json | 28 ++
.../forward_euler_method/code/elm/euler.elm | 332 ---------------
.../code/elm/src/Euler.elm | 397 ++++++++++++++++++
.../forward_euler_method.md | 6 +-
6 files changed, 431 insertions(+), 356 deletions(-)
delete mode 100644 contents/forward_euler_method/code/elm/elm-package.json
create mode 100644 contents/forward_euler_method/code/elm/elm.json
delete mode 100644 contents/forward_euler_method/code/elm/euler.elm
create mode 100644 contents/forward_euler_method/code/elm/src/Euler.elm
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index ee273e5af..695b0ffbf 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -89,7 +89,9 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get -y install --no-install-rec
## ?
# Setup Elm
-## https://github.com/elm/compiler/blob/master/installers/linux/README.md
+RUN mkdir -p ~/elm && curl -L -o ~/elm/elm.gz https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz && \
+ gunzip ~/elm/elm.gz && chmod +x ~/elm/elm
+ENV PATH=$PATH:~/elm
# Setup V
RUN mkdir -p ~/vlang && wget https://github.com/vlang/v/releases/download/weekly.2021.44/v_linux.zip -O ~/vlang/vlang.zip && \
diff --git a/contents/forward_euler_method/code/elm/elm-package.json b/contents/forward_euler_method/code/elm/elm-package.json
deleted file mode 100644
index fccb4595b..000000000
--- a/contents/forward_euler_method/code/elm/elm-package.json
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "version": "1.0.0",
- "summary": "helpful summary of your project, less than 80 characters",
- "repository": "https://github.com/user/project.git",
- "license": "BSD3",
- "source-directories": [
- "."
- ],
- "exposed-modules": [],
- "dependencies": {
- "CallumJHays/elm-sliders": "1.0.1 <= v < 2.0.0",
- "elm-lang/core": "5.1.1 <= v < 6.0.0",
- "elm-lang/html": "2.0.0 <= v < 3.0.0",
- "elm-lang/mouse": "1.0.1 <= v < 2.0.0",
- "elm-lang/svg": "2.0.0 <= v < 3.0.0",
- "elm-lang/window": "1.0.1 <= v < 2.0.0",
- "rtfeldman/hex": "1.0.0 <= v < 2.0.0"
- },
- "elm-version": "0.18.0 <= v < 0.19.0"
-}
diff --git a/contents/forward_euler_method/code/elm/elm.json b/contents/forward_euler_method/code/elm/elm.json
new file mode 100644
index 000000000..5eac761dd
--- /dev/null
+++ b/contents/forward_euler_method/code/elm/elm.json
@@ -0,0 +1,28 @@
+{
+ "type": "application",
+ "source-directories": [
+ "src"
+ ],
+ "elm-version": "0.19.1",
+ "dependencies": {
+ "direct": {
+ "bemyak/elm-slider": "1.0.0",
+ "elm/browser": "1.0.2",
+ "elm/core": "1.0.5",
+ "elm/html": "1.0.0",
+ "elm/json": "1.1.3",
+ "elm/svg": "1.0.1",
+ "elm/time": "1.0.0",
+ "rtfeldman/elm-hex": "1.0.0"
+ },
+ "indirect": {
+ "debois/elm-dom": "1.3.0",
+ "elm/url": "1.0.0",
+ "elm/virtual-dom": "1.0.2"
+ }
+ },
+ "test-dependencies": {
+ "direct": {},
+ "indirect": {}
+ }
+}
diff --git a/contents/forward_euler_method/code/elm/euler.elm b/contents/forward_euler_method/code/elm/euler.elm
deleted file mode 100644
index a8d8d3c89..000000000
--- a/contents/forward_euler_method/code/elm/euler.elm
+++ /dev/null
@@ -1,332 +0,0 @@
-module Euler exposing (..)
-
-import Html exposing (Html, div, button, text, h3)
-import Html.Attributes exposing (style)
-import Html.Events exposing (onClick, on)
-import Time exposing (Time, second)
-import Maybe exposing (withDefault)
-import Window exposing (Size, size)
-import Svg exposing (svg, circle, line, polyline)
-import Svg.Attributes exposing (width, height, stroke, x1, x2, y1, y2, cx, cy, r, points, fill)
-import Task exposing (perform)
-import Slider exposing (..)
-import Mouse
-import Json.Decode as Decode
-import Hex
-
-
-main =
- Html.program
- { init = init
- , view = view
- , update = update
- , subscriptions = subscriptions
- }
-
-
-
--- MODEL
-
-
-type alias Model =
- { part : Particle
- , dt : Time
- , dt0 : Time
- , t : Time
- , status : Status
- , wWidth : Int
- , wHeight : Int
- , history : List ( Time, Time, Particle )
- , drag : Maybe Drag
- }
-
-
-type alias Position =
- Float
-
-
-type alias Velocity =
- Float
-
-
-type alias Particle =
- { pos : List Position, vel : List Velocity }
-
-
-type Status
- = Idle
- | Running
-
-
-type alias Drag =
- { start : Position
- , current : Position
- }
-
-
-getX : Particle -> Position
-getX p =
- withDefault 0 <| List.head <| .pos p
-
-
-getV : Particle -> Velocity
-getV p =
- withDefault 0 <| List.head <| .vel p
-
-
-getX0 : Model -> Position
-getX0 m =
- let
- scale x =
- 3 - 6 * x / (toFloat m.wHeight)
- in
- case m.drag of
- Nothing ->
- getX m.part
-
- Just { start, current } ->
- getX m.part + scale current - scale start
-
-
-
--- INIT
-
-
-init : ( Model, Cmd Msg )
-init =
- ( Model (Particle [ x0 ] [ 0 ]) 0.5 0.5 0 Idle 0 0 [] Nothing, perform GetSize size )
-
-
-x0 : Position
-x0 =
- 2.5
-
-
-
--- UPDATE
-
-
-type Msg
- = Start
- | Stop
- | Tick Time
- | GetSize Size
- | SliderUpdate Float
- | DragStart Mouse.Position
- | DragAt Mouse.Position
- | DragEnd Mouse.Position
-
-
-update : Msg -> Model -> ( Model, Cmd Msg )
-update msg model =
- case msg of
- Start ->
- ( { model
- | status = Running
- , t = 0
- , dt = model.dt0
- , drag = Nothing
- }
- , Cmd.none
- )
-
- Stop ->
- ( { model
- | status = Idle
- , part = Particle [ x0 ] [ 0 ]
- , t = 0
- }
- , Cmd.none
- )
-
- Tick _ ->
- case model.status of
- Idle ->
- ( model, Cmd.none )
-
- Running ->
- if model.t > 5 + model.dt then
- ( { model
- | status = Idle
- , part = Particle [ x0 ] [ 0 ]
- , history = ( model.dt, model.t, model.part ) :: model.history
- , t = 0
- }
- , Cmd.none
- )
- else
- ( { model
- | part = evolve model.part model.t model.dt
- , t = model.t + model.dt
- }
- , perform GetSize size
- )
-
- GetSize s ->
- ( { model | wWidth = s.width, wHeight = s.height * 8 // 10 }, Cmd.none )
-
- SliderUpdate dt ->
- ( { model | dt0 = dt }, Cmd.none )
-
- DragStart { x, y } ->
- case model.status of
- Idle ->
- ( { model | drag = Just (Drag (toFloat y) (toFloat y)) }, Cmd.none )
-
- Running ->
- ( model, Cmd.none )
-
- DragAt { x, y } ->
- ( { model | drag = Maybe.map (\{ start } -> Drag start (toFloat y)) model.drag }
- , Cmd.none
- )
-
- DragEnd _ ->
- ( { model
- | drag = Nothing
- , part = Particle [ getX0 model ] [ k * getX0 model ]
- }
- , Cmd.none
- )
-
-
-k : Float
-k =
- -2
-
-
-diffEq : Position -> Velocity -> Time -> Time -> ( Position, Velocity )
-diffEq x v t dt =
- ( x + (k * x) * dt, k * (x + (k * x) * dt) )
-
-
-evolve : Particle -> Time -> Time -> Particle
-evolve p t dt =
- let
- ( x, v ) =
- diffEq (getX p) (getV p) t dt
- in
- { p | pos = x :: p.pos, vel = v :: p.vel }
-
-
-
--- SUBSCRIPTIONS
-
-
-subscriptions : Model -> Sub Msg
-subscriptions model =
- case model.drag of
- Nothing ->
- Time.every (model.dt * second) Tick
-
- Just _ ->
- Sub.batch [ Mouse.moves DragAt, Mouse.ups DragEnd ]
-
-
-
--- VIEW
-
-
-view : Model -> Html Msg
-view model =
- div []
- [ h3 [] [ text "Drag the ball up or down, pick a dt and click Start" ]
- , h3 [ style [ ( "color", gradient model.dt0 ) ] ]
- [ viewSlider
- , text ("dt = " ++ toString model.dt0)
- , button [ onClick Start ] [ text "Start" ]
- , button [ onClick Stop ] [ text "Stop" ]
- ]
- , svg
- [ width (toString model.wWidth)
- , height (toString model.wHeight)
- , stroke "black"
- ]
- ([ line
- [ x1 "0"
- , x2 (toString model.wWidth)
- , y1 (toString (model.wHeight // 2))
- , y2 (toString (model.wHeight // 2))
- ]
- []
- , line
- [ x1 (toString (model.wWidth // 20))
- , x2 (toString (model.wWidth // 20))
- , y1 "0"
- , y2 (toString model.wHeight)
- ]
- []
- , viewCircle model
- ]
- ++ (plotHistory model)
- )
- ]
-
-
-viewSlider : Html Msg
-viewSlider =
- props2view [ MinVal 0, MaxVal 1, Step 0.01, onChange SliderUpdate ]
-
-
-scaleX : Int -> Position -> String
-scaleX h x =
- toString (toFloat h / 2 * (1 - x / 3))
-
-
-scaleT : Int -> Time -> String
-scaleT w t =
- toString (toFloat w * (0.05 + t / 5))
-
-
-viewCircle : Model -> Html Msg
-viewCircle m =
- circle
- [ cy (scaleX m.wHeight (getX0 m))
- , cx (scaleT m.wWidth m.t)
- , r "10"
- , on "mousedown" (Decode.map DragStart Mouse.position)
- ]
- []
-
-
-plotPath : Int -> Int -> ( Time, Time, Particle ) -> String
-plotPath w h ( dt, tf, particle ) =
- let
- comb x ( t, s ) =
- ( t - dt, s ++ (scaleT w t) ++ "," ++ (scaleX h x) ++ " " )
- in
- Tuple.second <| List.foldl comb ( tf, "" ) particle.pos
-
-
-plotHistory : Model -> List (Html Msg)
-plotHistory m =
- let
- ( w, h ) =
- ( m.wWidth, m.wHeight )
- in
- List.map
- (\( dt, t, p ) ->
- polyline
- [ stroke "black"
- , fill "none"
- , stroke (gradient dt)
- , points (plotPath w h ( dt, t, p ))
- ]
- []
- )
- (( m.dt, m.t, m.part ) :: m.history)
-
-
-gradient : Time -> String
-gradient dt =
- let
- ( r, g, b ) =
- ( round (255 * dt), 0, round (255 * (1 - dt)) )
-
- col =
- Hex.toString (256 * (256 * r + g) + b)
- in
- if String.length col < 6 then
- "#" ++ String.repeat (6 - String.length col) "0" ++ col
- else
- "#" ++ col
diff --git a/contents/forward_euler_method/code/elm/src/Euler.elm b/contents/forward_euler_method/code/elm/src/Euler.elm
new file mode 100644
index 000000000..c9207d2de
--- /dev/null
+++ b/contents/forward_euler_method/code/elm/src/Euler.elm
@@ -0,0 +1,397 @@
+module Euler exposing (..)
+
+import Browser
+import Browser.Dom exposing (Viewport)
+import Browser.Events as Events
+import Hex
+import Html exposing (Html, button, div, h3, text)
+import Html.Attributes exposing (style)
+import Html.Events exposing (on, onClick)
+import Json.Decode as Decode exposing (Decoder)
+import Maybe
+import SingleSlider as Slider
+import Svg exposing (circle, line, polyline, svg)
+import Svg.Attributes exposing (cx, cy, fill, height, points, r, stroke, width, x1, x2, y1, y2)
+import Task
+import Time exposing (Posix)
+
+
+main : Platform.Program () Model Msg
+main =
+ Browser.element
+ { init = \() -> init
+ , view = view
+ , update = update
+ , subscriptions = subscriptions
+ }
+
+
+
+-- MODEL
+
+
+type alias Model =
+ { part : Particle
+ , dt : Time
+ , dt0 : Time
+ , t : Time
+ , status : Status
+ , wWidth : Float
+ , wHeight : Float
+ , history : List ( Time, Time, Particle )
+ , drag : Maybe Drag
+ , slider : Slider.Model
+ }
+
+
+x0 : Position
+x0 =
+ 2.5
+
+
+init : ( Model, Cmd Msg )
+init =
+ ( { part = Particle [ x0 ] [ 0 ]
+ , dt = 0.25
+ , dt0 = 0.25
+ , t = 0
+ , status = Idle
+ , wWidth = 0
+ , wHeight = 0
+ , history = []
+ , drag = Nothing
+ , slider =
+ { min = 0
+ , max = 1
+ , step = 0.01
+ , value = 0.25
+ , minFormatter = \_ -> ""
+ , maxFormatter = \_ -> ""
+ , currentValueFormatter = \_ _ -> ""
+ , disabled = False
+ }
+ }
+ , Task.perform GetViewPort Browser.Dom.getViewport
+ )
+
+
+type alias Time =
+ Float
+
+
+type alias Position =
+ Float
+
+
+type alias Velocity =
+ Float
+
+
+type alias Particle =
+ { pos : List Position, vel : List Velocity }
+
+
+type Status
+ = Idle
+ | Running
+
+
+type alias Drag =
+ { start : Float
+ , current : Float
+ }
+
+
+getX : Particle -> Position
+getX p =
+ Maybe.withDefault 0 <| List.head <| .pos p
+
+
+getV : Particle -> Velocity
+getV p =
+ Maybe.withDefault 0 <| List.head <| .vel p
+
+
+getX0 : Model -> Position
+getX0 m =
+ let
+ scale x =
+ 3 - 6 * x / m.wHeight
+ in
+ case m.drag of
+ Nothing ->
+ getX m.part
+
+ Just { start, current } ->
+ getX m.part + scale current - scale start
+
+
+resetParticle : Particle -> Particle
+resetParticle { pos, vel } =
+ case ( List.reverse pos, List.reverse vel ) of
+ ( x :: _, v :: _ ) ->
+ Particle [ x ] [ v ]
+
+ _ ->
+ Particle [ x0 ] [ 0 ]
+
+
+
+-- UPDATE
+
+
+type Msg
+ = Start
+ | Stop
+ | Tick Posix
+ | GetViewPort Viewport
+ | SliderUpdate Float
+ | SliderMsg Slider.Msg
+ | DragStart Float
+ | DragAt Float
+ | DragEnd Float
+
+
+update : Msg -> Model -> ( Model, Cmd Msg )
+update msg model =
+ case msg of
+ Start ->
+ ( { model
+ | status = Running
+ , t = 0
+ , dt = model.dt0
+ , drag = Nothing
+ , part = resetParticle model.part
+ }
+ , Cmd.none
+ )
+
+ Stop ->
+ ( { model
+ | status = Idle
+ , part = resetParticle model.part
+ , t = 0
+ }
+ , Cmd.none
+ )
+
+ Tick _ ->
+ case model.status of
+ Idle ->
+ ( model, Cmd.none )
+
+ Running ->
+ if model.t > 5 + model.dt then
+ ( { model
+ | status = Idle
+ , part = Particle [ x0 ] [ 0 ]
+ , history = ( model.dt, model.t, model.part ) :: model.history
+ , t = 0
+ }
+ , Cmd.none
+ )
+
+ else
+ ( { model
+ | part = evolve model.part model.t model.dt
+ , t = model.t + model.dt
+ }
+ , Task.perform GetViewPort Browser.Dom.getViewport
+ )
+
+ GetViewPort { viewport } ->
+ ( { model | wWidth = viewport.width, wHeight = viewport.height * 8 / 10 }, Cmd.none )
+
+ SliderUpdate dt ->
+ ( { model | dt0 = dt }, Cmd.none )
+
+ SliderMsg sliderMsg ->
+ let
+ ( newSlider, cmd, updateResults ) =
+ Slider.update sliderMsg model.slider
+
+ newModel =
+ { model | slider = newSlider, dt0 = newSlider.value }
+
+ newCmd =
+ if updateResults then
+ Cmd.batch [ Cmd.map SliderMsg cmd, Cmd.none ]
+
+ else
+ Cmd.none
+ in
+ ( newModel, newCmd )
+
+ DragStart y ->
+ case model.status of
+ Idle ->
+ ( { model | drag = Just (Drag y y) }, Cmd.none )
+
+ Running ->
+ ( model, Cmd.none )
+
+ DragAt y ->
+ ( { model | drag = Maybe.map (\{ start } -> Drag start y) model.drag }
+ , Cmd.none
+ )
+
+ DragEnd _ ->
+ ( { model
+ | drag = Nothing
+ , part = Particle [ getX0 model ] [ k * getX0 model ]
+ }
+ , Cmd.none
+ )
+
+
+k : Float
+k =
+ -2
+
+
+diffEq : Position -> Velocity -> Time -> Time -> ( Position, Velocity )
+diffEq x _ _ dt =
+ ( x + (k * x) * dt, k * (x + (k * x) * dt) )
+
+
+evolve : Particle -> Time -> Time -> Particle
+evolve p t dt =
+ let
+ ( x, v ) =
+ diffEq (getX p) (getV p) t dt
+ in
+ { p | pos = x :: p.pos, vel = v :: p.vel }
+
+
+
+-- SUBSCRIPTIONS
+
+
+subscriptions : Model -> Sub Msg
+subscriptions model =
+ (Slider.subscriptions model.slider |> Sub.map SliderMsg)
+ :: (case model.drag of
+ Nothing ->
+ [ Time.every (model.dt * 1000) Tick ]
+
+ Just _ ->
+ [ Events.onMouseMove (Decode.map DragAt decodeMouseHeight)
+ , Events.onMouseUp (Decode.map DragEnd decodeMouseHeight)
+ ]
+ )
+ |> Sub.batch
+
+
+decodeMouseHeight : Decoder Float
+decodeMouseHeight =
+ Decode.field "pageY" Decode.float
+
+
+
+-- VIEW
+
+
+view : Model -> Html Msg
+view model =
+ div []
+ [ h3 [] [ text "Drag the ball up or down, pick a dt and click Start" ]
+ , h3 [ style "color" (gradient model.dt0) ]
+ [ viewSlider model.slider
+ , button [ onClick Start ] [ text "Start" ]
+ , button [ onClick Stop ] [ text "Stop" ]
+ , text ("dt = " ++ String.fromFloat model.dt0)
+ ]
+ , svg
+ [ width (String.fromFloat model.wWidth)
+ , height (String.fromFloat model.wHeight)
+ , stroke "black"
+ ]
+ ([ line
+ [ x1 "0"
+ , x2 (String.fromFloat model.wWidth)
+ , y1 (String.fromFloat (model.wHeight / 2))
+ , y2 (String.fromFloat (model.wHeight / 2))
+ ]
+ []
+ , line
+ [ x1 (String.fromFloat (model.wWidth / 20))
+ , x2 (String.fromFloat (model.wWidth / 20))
+ , y1 "0"
+ , y2 (String.fromFloat model.wHeight)
+ ]
+ []
+ , viewCircle model
+ ]
+ ++ plotHistory model
+ )
+ ]
+
+
+viewSlider : Slider.Model -> Html Msg
+viewSlider slider =
+ Slider.view slider |> Html.map SliderMsg
+
+
+scaleX : Float -> Position -> String
+scaleX h x =
+ String.fromFloat (h / 2 * (1 - x / 3))
+
+
+scaleT : Float -> Time -> String
+scaleT w t =
+ String.fromFloat (w * (0.05 + t / 5))
+
+
+viewCircle : Model -> Html Msg
+viewCircle m =
+ circle
+ [ cy (scaleX m.wHeight (getX0 m))
+ , cx (scaleT m.wWidth m.t)
+ , r "10"
+ , on "mousedown" (Decode.map DragStart decodeMouseHeight)
+ ]
+ []
+
+
+plotPath : Float -> Float -> ( Time, Time, Particle ) -> String
+plotPath w h ( dt, tf, particle ) =
+ let
+ comb x ( t, s ) =
+ ( t - dt, s ++ scaleT w t ++ "," ++ scaleX h x ++ " " )
+ in
+ Tuple.second <| List.foldl comb ( tf, "" ) particle.pos
+
+
+plotHistory : Model -> List (Html Msg)
+plotHistory m =
+ let
+ ( w, h ) =
+ ( m.wWidth, m.wHeight )
+ in
+ List.map
+ (\( dt, t, p ) ->
+ polyline
+ [ stroke "black"
+ , fill "none"
+ , stroke (gradient dt)
+ , points (plotPath w h ( dt, t, p ))
+ ]
+ []
+ )
+ (( m.dt, m.t, m.part ) :: m.history)
+
+
+gradient : Time -> String
+gradient dt =
+ let
+ ( r, g, b ) =
+ ( round (255 * dt), 0, round (255 * (1 - dt)) )
+
+ col =
+ Hex.toString (256 * (256 * r + g) + b)
+ in
+ if String.length col < 6 then
+ "#" ++ String.repeat (6 - String.length col) "0" ++ col
+
+ else
+ "#" ++ col
diff --git a/contents/forward_euler_method/forward_euler_method.md b/contents/forward_euler_method/forward_euler_method.md
index 175ef1337..d4aa7375c 100644
--- a/contents/forward_euler_method/forward_euler_method.md
+++ b/contents/forward_euler_method/forward_euler_method.md
@@ -116,11 +116,11 @@ Note that in this case, the velocity is directly given by the ODE and the accele
{% sample lang="rs" %}
[import, lang:"rust"](code/rust/euler.rs)
{% sample lang="elm" %}
-[import:44-54, lang:"elm"](code/elm/euler.elm)
-[import:193-210, lang:"elm"](code/elm/euler.elm)
+[import:78-91, lang:"elm"](code/elm/src/Euler.elm)
+[import:236-252, lang:"elm"](code/elm/src/Euler.elm)
Full code for the visualization follows:
-[import, lang:"elm"](code/elm/euler.elm)
+[import, lang:"elm"](code/elm/src/Euler.elm)
{% sample lang="py" %}
[import, lang:"python"](code/python/euler.py)
From 7fe5bfe9e5a7972916d4edc874165d498bcaacba Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Sun, 7 Nov 2021 16:25:18 +0100
Subject: [PATCH 067/146] Standardise code directory names (#920)
* Rename c++ directories to cpp
* Rename golang folders to go
* Change paths to code in chapter files
Co-authored-by: James Schloss
---
contents/IFS/IFS.md | 4 +--
contents/IFS/code/{c++ => cpp}/IFS.cpp | 0
.../approximate_counting.md | 2 +-
.../{c++ => cpp}/approximate_counting.cpp | 0
contents/barnsley/barnsley.md | 2 +-
.../barnsley/code/{c++ => cpp}/barnsley.cpp | 0
.../code/{c++ => cpp}/gauss_easter.cpp | 0
contents/computus/computus.md | 2 +-
.../cooley_tukey/code/{c++ => cpp}/fft.cpp | 0
contents/cooley_tukey/cooley_tukey.md | 6 ++--
.../code/{c++ => cpp}/euclidean.cpp | 0
.../euclidean_algorithm.md | 6 ++--
.../code/{c++ => cpp}/euler.cpp | 0
.../code/{golang => go}/euler.go | 0
.../forward_euler_method.md | 4 +--
.../{c++ => cpp}/gaussian_elimination.cpp | 0
.../gaussian_elimination.md | 12 ++++----
.../code/{c++ => cpp}/graham_scan.cpp | 0
.../graham_scan/code/{golang => go}/graham.go | 0
contents/graham_scan/graham_scan.md | 12 ++++----
.../code/{c++ => cpp}/huffman.cpp | 0
.../code/{golang => go}/huffman.go | 0
contents/huffman_encoding/huffman_encoding.md | 4 +--
.../code/{c++ => cpp}/jarvis_march.cpp | 0
.../code/{golang => go}/jarvis.go | 0
contents/jarvis_march/jarvis_march.md | 4 +--
.../code/{c++ => cpp}/monte_carlo.cpp | 0
.../monte_carlo_integration.md | 4 +--
contents/quantum_systems/quantum_systems.md | 2 +-
.../code/{c++ => cpp}/split_op.cpp | 0
.../split-operator_method.md | 8 +++---
.../code/{c++ => cpp}/stable_marriage.cpp | 0
.../stable_marriage_problem.md | 2 +-
.../code/{c++ => cpp}/thomas.cpp | 0
.../code/{golang => go}/thomas.go | 0
contents/thomas_algorithm/thomas_algorithm.md | 4 +--
.../code/{c++ => cpp}/tree_example.cpp | 0
.../code/{golang => go}/treetraversal.go | 0
contents/tree_traversal/tree_traversal.md | 28 +++++++++----------
.../code/{c++ => cpp}/verlet.cpp | 0
.../code/{golang => go}/verlet.go | 0
.../verlet_integration/verlet_integration.md | 16 +++++------
42 files changed, 61 insertions(+), 61 deletions(-)
rename contents/IFS/code/{c++ => cpp}/IFS.cpp (100%)
rename contents/approximate_counting/code/{c++ => cpp}/approximate_counting.cpp (100%)
rename contents/barnsley/code/{c++ => cpp}/barnsley.cpp (100%)
rename contents/computus/code/{c++ => cpp}/gauss_easter.cpp (100%)
rename contents/cooley_tukey/code/{c++ => cpp}/fft.cpp (100%)
rename contents/euclidean_algorithm/code/{c++ => cpp}/euclidean.cpp (100%)
rename contents/forward_euler_method/code/{c++ => cpp}/euler.cpp (100%)
rename contents/forward_euler_method/code/{golang => go}/euler.go (100%)
rename contents/gaussian_elimination/code/{c++ => cpp}/gaussian_elimination.cpp (100%)
rename contents/graham_scan/code/{c++ => cpp}/graham_scan.cpp (100%)
rename contents/graham_scan/code/{golang => go}/graham.go (100%)
rename contents/huffman_encoding/code/{c++ => cpp}/huffman.cpp (100%)
rename contents/huffman_encoding/code/{golang => go}/huffman.go (100%)
rename contents/jarvis_march/code/{c++ => cpp}/jarvis_march.cpp (100%)
rename contents/jarvis_march/code/{golang => go}/jarvis.go (100%)
rename contents/monte_carlo_integration/code/{c++ => cpp}/monte_carlo.cpp (100%)
rename contents/split-operator_method/code/{c++ => cpp}/split_op.cpp (100%)
rename contents/stable_marriage_problem/code/{c++ => cpp}/stable_marriage.cpp (100%)
rename contents/thomas_algorithm/code/{c++ => cpp}/thomas.cpp (100%)
rename contents/thomas_algorithm/code/{golang => go}/thomas.go (100%)
rename contents/tree_traversal/code/{c++ => cpp}/tree_example.cpp (100%)
rename contents/tree_traversal/code/{golang => go}/treetraversal.go (100%)
rename contents/verlet_integration/code/{c++ => cpp}/verlet.cpp (100%)
rename contents/verlet_integration/code/{golang => go}/verlet.go (100%)
diff --git a/contents/IFS/IFS.md b/contents/IFS/IFS.md
index 2ed1fe484..9431e4631 100644
--- a/contents/IFS/IFS.md
+++ b/contents/IFS/IFS.md
@@ -135,7 +135,7 @@ Here, instead of tracking children of children, we track a single individual tha
{% sample lang="hs" %}
[import:7-13, lang:"haskell"](code/haskell/IFS.hs)
{% sample lang="cpp" %}
-[import:39-52, lang:"cpp"](code/c++/IFS.cpp)
+[import:39-52, lang:"cpp"](code/cpp/IFS.cpp)
{% sample lang="py" %}
[import:5-12, lang:"python"](code/python/IFS.py)
{% sample lang="c" %}
@@ -221,7 +221,7 @@ In addition, we have written the chaos game code to take in a set of points so t
{% sample lang="hs" %}
[import, lang:"haskell"](code/haskell/IFS.hs)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/IFS.cpp)
+[import, lang:"cpp"](code/cpp/IFS.cpp)
{% sample lang="py" %}
[import, lang:"python"](code/python/IFS.py)
{% sample lang="c" %}
diff --git a/contents/IFS/code/c++/IFS.cpp b/contents/IFS/code/cpp/IFS.cpp
similarity index 100%
rename from contents/IFS/code/c++/IFS.cpp
rename to contents/IFS/code/cpp/IFS.cpp
diff --git a/contents/approximate_counting/approximate_counting.md b/contents/approximate_counting/approximate_counting.md
index 654721844..ae4a765d6 100644
--- a/contents/approximate_counting/approximate_counting.md
+++ b/contents/approximate_counting/approximate_counting.md
@@ -363,7 +363,7 @@ As we do not have any objects to count, we will instead simulate the counting wi
{% sample lang="c" %}
[import, lang:"c"](code/c/approximate_counting.c)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/approximate_counting.cpp)
+[import, lang:"cpp"](code/cpp/approximate_counting.cpp)
{% sample lang="python" %}
[import, lang:"python"](code/python/approximate_counting.py)
{% endmethod %}
diff --git a/contents/approximate_counting/code/c++/approximate_counting.cpp b/contents/approximate_counting/code/cpp/approximate_counting.cpp
similarity index 100%
rename from contents/approximate_counting/code/c++/approximate_counting.cpp
rename to contents/approximate_counting/code/cpp/approximate_counting.cpp
diff --git a/contents/barnsley/barnsley.md b/contents/barnsley/barnsley.md
index f696b9ffb..c879d7bbd 100644
--- a/contents/barnsley/barnsley.md
+++ b/contents/barnsley/barnsley.md
@@ -128,7 +128,7 @@ The biggest differences between the two code implementations is that the Barnsle
{% sample lang="rs" %}
[import, lang:"rust"](code/rust/src/main.rs)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/barnsley.cpp)
+[import, lang:"cpp"](code/cpp/barnsley.cpp)
{% sample lang="c" %}
[import, lang:"c"](code/c/barnsley.c)
{% sample lang="java" %}
diff --git a/contents/barnsley/code/c++/barnsley.cpp b/contents/barnsley/code/cpp/barnsley.cpp
similarity index 100%
rename from contents/barnsley/code/c++/barnsley.cpp
rename to contents/barnsley/code/cpp/barnsley.cpp
diff --git a/contents/computus/code/c++/gauss_easter.cpp b/contents/computus/code/cpp/gauss_easter.cpp
similarity index 100%
rename from contents/computus/code/c++/gauss_easter.cpp
rename to contents/computus/code/cpp/gauss_easter.cpp
diff --git a/contents/computus/computus.md b/contents/computus/computus.md
index 0b474c9a9..3a881cdb0 100644
--- a/contents/computus/computus.md
+++ b/contents/computus/computus.md
@@ -315,7 +315,7 @@ For now, we have the code outputting a tuple of $$d$$ and $$e$$, so users can us
{% sample lang="c" %}
[import, lang:"c"](code/c/gauss_easter.c)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/gauss_easter.cpp)
+[import, lang:"cpp"](code/cpp/gauss_easter.cpp)
{% sample lang="lisp" %}
[import, lang:"lisp"](code/clisp/gauss-easter.lisp)
{% sample lang="nim" %}
diff --git a/contents/cooley_tukey/code/c++/fft.cpp b/contents/cooley_tukey/code/cpp/fft.cpp
similarity index 100%
rename from contents/cooley_tukey/code/c++/fft.cpp
rename to contents/cooley_tukey/code/cpp/fft.cpp
diff --git a/contents/cooley_tukey/cooley_tukey.md b/contents/cooley_tukey/cooley_tukey.md
index 67309b5d2..b30052e40 100644
--- a/contents/cooley_tukey/cooley_tukey.md
+++ b/contents/cooley_tukey/cooley_tukey.md
@@ -76,7 +76,7 @@ For some reason, though, putting code to this transformation really helped me fi
{% sample lang="clj" %}
[import:15-30, lang:"clojure"](code/clojure/fft.clj)
{% sample lang="cpp" %}
-[import:23-33, lang:"cpp"](code/c++/fft.cpp)
+[import:23-33, lang:"cpp"](code/cpp/fft.cpp)
{% sample lang="hs" %}
[import:7-13, lang:"haskell"](code/haskell/fft.hs)
{% sample lang="py" %}
@@ -129,7 +129,7 @@ In the end, the code looks like:
{% sample lang="clj" %}
[import:31-58, lang:"clojure"](code/clojure/fft.clj)
{% sample lang="cpp" %}
-[import:36-66, lang:"cpp"](code/c++/fft.cpp)
+[import:36-66, lang:"cpp"](code/cpp/fft.cpp)
{% sample lang="hs" %}
[import:15-28, lang:"haskell"](code/haskell/fft.hs)
{% sample lang="py" %}
@@ -242,7 +242,7 @@ Note: I implemented this in Julia because the code seems more straightforward in
{% sample lang="clj" %}
[import, lang:"clojure"](code/clojure/fft.clj)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/fft.cpp)
+[import, lang:"cpp"](code/cpp/fft.cpp)
{% sample lang="hs" %}
[import, lang:"haskell"](code/haskell/fft.hs)
{% sample lang="py" %}
diff --git a/contents/euclidean_algorithm/code/c++/euclidean.cpp b/contents/euclidean_algorithm/code/cpp/euclidean.cpp
similarity index 100%
rename from contents/euclidean_algorithm/code/c++/euclidean.cpp
rename to contents/euclidean_algorithm/code/cpp/euclidean.cpp
diff --git a/contents/euclidean_algorithm/euclidean_algorithm.md b/contents/euclidean_algorithm/euclidean_algorithm.md
index f44c3acb7..1d6211a37 100644
--- a/contents/euclidean_algorithm/euclidean_algorithm.md
+++ b/contents/euclidean_algorithm/euclidean_algorithm.md
@@ -14,7 +14,7 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
{% sample lang="clj" %}
[import:2-8, lang="clojure"](code/clojure/euclidean_example.clj)
{% sample lang="cpp" %}
-[import:18-31, lang="c_cpp"](code/c++/euclidean.cpp)
+[import:18-31, lang="c_cpp"](code/cpp/euclidean.cpp)
{% sample lang="java" %}
[import:3-16, lang="java"](code/java/EuclideanAlgo.java)
{% sample lang="kotlin" %}
@@ -104,7 +104,7 @@ Modern implementations, though, often use the modulus operator (%) like so
{% sample lang="clj" %}
[import:9-13, lang="clojure"](code/clojure/euclidean_example.clj)
{% sample lang="cpp" %}
-[import:5-15, lang="c_cpp"](code/c++/euclidean.cpp)
+[import:5-15, lang="c_cpp"](code/cpp/euclidean.cpp)
{% sample lang="java" %}
[import:18-26, lang="java"](code/java/EuclideanAlgo.java)
{% sample lang="kotlin" %}
@@ -207,7 +207,7 @@ Here's a video on the Euclidean algorithm:
{% sample lang="clj" %}
[import, lang="clojure"](code/clojure/euclidean_example.clj)
{% sample lang="cpp" %}
-[import, lang="c_cpp"](code/c++/euclidean.cpp)
+[import, lang="c_cpp"](code/cpp/euclidean.cpp)
{% sample lang="java" %}
[import, lang="java"](code/java/EuclideanAlgo.java)
{% sample lang="kotlin" %}
diff --git a/contents/forward_euler_method/code/c++/euler.cpp b/contents/forward_euler_method/code/cpp/euler.cpp
similarity index 100%
rename from contents/forward_euler_method/code/c++/euler.cpp
rename to contents/forward_euler_method/code/cpp/euler.cpp
diff --git a/contents/forward_euler_method/code/golang/euler.go b/contents/forward_euler_method/code/go/euler.go
similarity index 100%
rename from contents/forward_euler_method/code/golang/euler.go
rename to contents/forward_euler_method/code/go/euler.go
diff --git a/contents/forward_euler_method/forward_euler_method.md b/contents/forward_euler_method/forward_euler_method.md
index d4aa7375c..f97ff27a2 100644
--- a/contents/forward_euler_method/forward_euler_method.md
+++ b/contents/forward_euler_method/forward_euler_method.md
@@ -112,7 +112,7 @@ Note that in this case, the velocity is directly given by the ODE and the accele
{% sample lang="c" %}
[import, lang:"c"](code/c/euler.c)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/euler.cpp)
+[import, lang:"cpp"](code/cpp/euler.cpp)
{% sample lang="rs" %}
[import, lang:"rust"](code/rust/euler.rs)
{% sample lang="elm" %}
@@ -135,7 +135,7 @@ Full code for the visualization follows:
{% sample lang="f90" %}
[import, lang:"fortran"](code/fortran/euler.f90)
{% sample lang="go" %}
-[import, lang:"go"](code/golang/euler.go)
+[import, lang:"go"](code/go/euler.go)
{% sample lang="v" %}
[import, lang:"v"](code/v/euler.v)
{% sample lang="asm-x64" %}
diff --git a/contents/gaussian_elimination/code/c++/gaussian_elimination.cpp b/contents/gaussian_elimination/code/cpp/gaussian_elimination.cpp
similarity index 100%
rename from contents/gaussian_elimination/code/c++/gaussian_elimination.cpp
rename to contents/gaussian_elimination/code/cpp/gaussian_elimination.cpp
diff --git a/contents/gaussian_elimination/gaussian_elimination.md b/contents/gaussian_elimination/gaussian_elimination.md
index 7f8e005af..8caf869ed 100644
--- a/contents/gaussian_elimination/gaussian_elimination.md
+++ b/contents/gaussian_elimination/gaussian_elimination.md
@@ -315,7 +315,7 @@ In code, this process might look like this:
[import:5-13, lang:"c"](code/c/gaussian_elimination.c)
[import:19-34, lang:"c"](code/c/gaussian_elimination.c)
{% sample lang="cpp" %}
-[import:13-23, lang:"cpp"](code/c++/gaussian_elimination.cpp)
+[import:13-23, lang:"cpp"](code/cpp/gaussian_elimination.cpp)
{% sample lang="hs" %}
[import:10-17, lang:"haskell"](code/haskell/gaussianElimination.hs)
[import:44-46, lang:"haskell"](code/haskell/gaussianElimination.hs)
@@ -389,7 +389,7 @@ Here is what it might look like in code:
{% sample lang="c" %}
[import:36-41, lang:"c"](code/c/gaussian_elimination.c)
{% sample lang="cpp" %}
-[import:25-32, lang:"cpp"](code/c++/gaussian_elimination.cpp)
+[import:25-32, lang:"cpp"](code/cpp/gaussian_elimination.cpp)
{% sample lang="hs" %}
[import:19-33, lang:"haskell"](code/haskell/gaussianElimination.hs)
[import:42-42, lang:"haskell"](code/haskell/gaussianElimination.hs)
@@ -412,7 +412,7 @@ When we put everything together, it looks like this:
{% sample lang="c" %}
[import:15-48, lang:"c"](code/c/gaussian_elimination.c)
{% sample lang="cpp" %}
-[import:8-34, lang:"cpp"](code/c++/gaussian_elimination.cpp)
+[import:8-34, lang:"cpp"](code/cpp/gaussian_elimination.cpp)
{% sample lang="hs" %}
[import:10-36, lang:"haskell"](code/haskell/gaussianElimination.hs)
{% sample lang="py" %}
@@ -453,7 +453,7 @@ Here it is in code:
{% sample lang="c" %}
[import:64-82, lang:"c"](code/c/gaussian_elimination.c)
{% sample lang="cpp" %}
-[import:36-54, lang:"cpp"](code/c++/gaussian_elimination.cpp)
+[import:36-54, lang:"cpp"](code/cpp/gaussian_elimination.cpp)
{% sample lang="hs" %}
[import:38-46, lang:"haskell"](code/haskell/gaussianElimination.hs)
{% sample lang="py" %}
@@ -497,7 +497,7 @@ In code, it looks like this:
{% sample lang="c" %}
[import:50-62, lang:"c"](code/c/gaussian_elimination.c)
{% sample lang="cpp" %}
-[import:56-72, lang:"cpp"](code/c++/gaussian_elimination.cpp)
+[import:56-72, lang:"cpp"](code/cpp/gaussian_elimination.cpp)
{% sample lang="rs" %}
[import:98-112, lang:"rust"](code/rust/gaussian_elimination.rs)
{% sample lang="hs" %}
@@ -567,7 +567,7 @@ Here's a video describing Gaussian elimination:
{% sample lang="c" %}
[import, lang:"c"](code/c/gaussian_elimination.c)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/gaussian_elimination.cpp)
+[import, lang:"cpp"](code/cpp/gaussian_elimination.cpp)
{% sample lang="rs" %}
[import, lang:"rust"](code/rust/gaussian_elimination.rs)
{% sample lang="hs" %}
diff --git a/contents/graham_scan/code/c++/graham_scan.cpp b/contents/graham_scan/code/cpp/graham_scan.cpp
similarity index 100%
rename from contents/graham_scan/code/c++/graham_scan.cpp
rename to contents/graham_scan/code/cpp/graham_scan.cpp
diff --git a/contents/graham_scan/code/golang/graham.go b/contents/graham_scan/code/go/graham.go
similarity index 100%
rename from contents/graham_scan/code/golang/graham.go
rename to contents/graham_scan/code/go/graham.go
diff --git a/contents/graham_scan/graham_scan.md b/contents/graham_scan/graham_scan.md
index 586d209db..7b84f3acd 100644
--- a/contents/graham_scan/graham_scan.md
+++ b/contents/graham_scan/graham_scan.md
@@ -23,13 +23,13 @@ We can find whether a rotation is counter-clockwise with trigonometric functions
{% sample lang="py" %}
[import:4-6, lang:"python"](code/python/graham_scan.py)
{% sample lang="go" %}
-[import:13-15, lang:"go"](code/golang/graham.go)
+[import:13-15, lang:"go"](code/go/graham.go)
{% sample lang="java" %}
[import:27-29, lang:"java"](code/java/GrahamScan.java)
{% sample lang="lisp" %}
[import:5-13, lang:"lisp"](code/clisp/graham-scan.lisp)
{% sample lang="cpp" %}
-[import:18-20, lang="cpp"](code/c++/graham_scan.cpp)
+[import:18-20, lang="cpp"](code/cpp/graham_scan.cpp)
{% sample lang="coco" %}
[import:4-8, lang="coconut"](code/coconut/graham_scan.coco)
{% endmethod %}
@@ -57,13 +57,13 @@ In the end, the code should look something like this:
{% sample lang="py" %}
[import:14-28, lang:"python"](code/python/graham_scan.py)
{% sample lang="go" %}
-[import:21-42, lang:"go"](code/golang/graham.go)
+[import:21-42, lang:"go"](code/go/graham.go)
{% sample lang="java" %}
[import:35-70, lang:"java"](code/java/GrahamScan.java)
{% sample lang="lisp" %}
[import:15-58, lang:"lisp"](code/clisp/graham-scan.lisp)
{% sample lang="cpp" %}
-[import:26-62, lang="cpp"](code/c++/graham_scan.cpp)
+[import:26-62, lang="cpp"](code/cpp/graham_scan.cpp)
{% sample lang="coco" %}
[import:17-30, lang="coconut"](code/coconut/graham_scan.coco)
{% endmethod %}
@@ -86,13 +86,13 @@ In the end, the code should look something like this:
{% sample lang="py" %}
[import, lang:"python"](code/python/graham_scan.py)
{% sample lang="go" %}
-[import, lang:"go"](code/golang/graham.go)
+[import, lang:"go"](code/go/graham.go)
{% sample lang="java" %}
[import, lang:"java"](code/java/GrahamScan.java)
{% sample lang="lisp" %}
[import, lang:"lisp"](code/clisp/graham-scan.lisp)
{% sample lang="cpp" %}
-[import, lang="cpp"](code/c++/graham_scan.cpp)
+[import, lang="cpp"](code/cpp/graham_scan.cpp)
{%sample lang="coco" %}
[import, lang="coconut"](code/coconut/graham_scan.coco)
{% endmethod %}
diff --git a/contents/huffman_encoding/code/c++/huffman.cpp b/contents/huffman_encoding/code/cpp/huffman.cpp
similarity index 100%
rename from contents/huffman_encoding/code/c++/huffman.cpp
rename to contents/huffman_encoding/code/cpp/huffman.cpp
diff --git a/contents/huffman_encoding/code/golang/huffman.go b/contents/huffman_encoding/code/go/huffman.go
similarity index 100%
rename from contents/huffman_encoding/code/golang/huffman.go
rename to contents/huffman_encoding/code/go/huffman.go
diff --git a/contents/huffman_encoding/huffman_encoding.md b/contents/huffman_encoding/huffman_encoding.md
index 44bc1e783..3772c97ca 100644
--- a/contents/huffman_encoding/huffman_encoding.md
+++ b/contents/huffman_encoding/huffman_encoding.md
@@ -78,7 +78,7 @@ Whether you use a stack or straight-up recursion also depends on the language, b
{% sample lang="lua" %}
[import, lang="lua"](code/lua/huffman.lua)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/huffman.cpp)
+[import, lang:"cpp"](code/cpp/huffman.cpp)
{% sample lang="clj" %}
[import, lang:"clojure"](code/clojure/huffman.clj)
{% sample lang="py" %}
@@ -88,7 +88,7 @@ Whether you use a stack or straight-up recursion also depends on the language, b
{% sample lang="java" %}
[import, lang:"java"](code/java/huffman.java)
{% sample lang="go" %}
-[import, lang:"go"](code/golang/huffman.go)
+[import, lang:"go"](code/go/huffman.go)
{% sample lang="asm-x64" %}
[import, lang:"asm-x64"](code/asm-x64/huffman.s)
{% sample lang="scala" %}
diff --git a/contents/jarvis_march/code/c++/jarvis_march.cpp b/contents/jarvis_march/code/cpp/jarvis_march.cpp
similarity index 100%
rename from contents/jarvis_march/code/c++/jarvis_march.cpp
rename to contents/jarvis_march/code/cpp/jarvis_march.cpp
diff --git a/contents/jarvis_march/code/golang/jarvis.go b/contents/jarvis_march/code/go/jarvis.go
similarity index 100%
rename from contents/jarvis_march/code/golang/jarvis.go
rename to contents/jarvis_march/code/go/jarvis.go
diff --git a/contents/jarvis_march/jarvis_march.md b/contents/jarvis_march/jarvis_march.md
index fa244713e..20929d4ad 100644
--- a/contents/jarvis_march/jarvis_march.md
+++ b/contents/jarvis_march/jarvis_march.md
@@ -39,13 +39,13 @@ Since this algorithm, there have been many other algorithms that have advanced t
{% sample lang="py" %}
[import, lang:"python"](code/python/jarvis_march.py)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/jarvis_march.cpp)
+[import, lang:"cpp"](code/cpp/jarvis_march.cpp)
{% sample lang="lisp" %}
[import, lang:"lisp"](code/clisp/jarvis-march.lisp)
{% sample lang="java" %}
[import, lang:"java"](code/java/JarvisMarch.java)
{% sample lang="go" %}
-[import, lang:"go"](code/golang/jarvis.go)
+[import, lang:"go"](code/go/jarvis.go)
{% sample lang="v" %}
[import, lang:"v"](code/v/jarvis.v)
{% sample lang="rust" %}
diff --git a/contents/monte_carlo_integration/code/c++/monte_carlo.cpp b/contents/monte_carlo_integration/code/cpp/monte_carlo.cpp
similarity index 100%
rename from contents/monte_carlo_integration/code/c++/monte_carlo.cpp
rename to contents/monte_carlo_integration/code/cpp/monte_carlo.cpp
diff --git a/contents/monte_carlo_integration/monte_carlo_integration.md b/contents/monte_carlo_integration/monte_carlo_integration.md
index cf5640ffa..964de7bbe 100644
--- a/contents/monte_carlo_integration/monte_carlo_integration.md
+++ b/contents/monte_carlo_integration/monte_carlo_integration.md
@@ -44,7 +44,7 @@ each point is tested to see whether it's in the circle or not:
{% sample lang="c" %}
[import:7-9, lang:"c"](code/c/monte_carlo.c)
{% sample lang="cpp" %}
-[import:7-16, lang:"cpp"](code/c++/monte_carlo.cpp)
+[import:7-16, lang:"cpp"](code/cpp/monte_carlo.cpp)
{% sample lang="js" %}
[import:2-6, lang:"javascript"](code/javascript/monte_carlo.js)
{% sample lang="hs" %}
@@ -147,7 +147,7 @@ Feel free to submit your version via pull request, and thanks for reading!
{% sample lang="c" %}
[import, lang:"c"](code/c/monte_carlo.c)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/monte_carlo.cpp)
+[import, lang:"cpp"](code/cpp/monte_carlo.cpp)
{% sample lang="js" %}
[import, lang:"javascript"](code/javascript/monte_carlo.js)
{% sample lang="hs" %}
diff --git a/contents/quantum_systems/quantum_systems.md b/contents/quantum_systems/quantum_systems.md
index a7a762ca5..c602aaea1 100644
--- a/contents/quantum_systems/quantum_systems.md
+++ b/contents/quantum_systems/quantum_systems.md
@@ -232,7 +232,7 @@ This ultimately looks like this:
{% sample lang="c" %}
[import:150-184, lang:"c"](../split-operator_method/code/c/split_op.c)
{% sample lang="cpp" %}
-[import:158-189, lang:"cpp"](../split-operator_method/code/c++/split_op.cpp)
+[import:158-189, lang:"cpp"](../split-operator_method/code/cpp/split_op.cpp)
{% sample lang="py" %}
[import:98-112, lang:"python"](../split-operator_method/code/python/split_op.py)
{% endmethod %}
diff --git a/contents/split-operator_method/code/c++/split_op.cpp b/contents/split-operator_method/code/cpp/split_op.cpp
similarity index 100%
rename from contents/split-operator_method/code/c++/split_op.cpp
rename to contents/split-operator_method/code/cpp/split_op.cpp
diff --git a/contents/split-operator_method/split-operator_method.md b/contents/split-operator_method/split-operator_method.md
index 33af1f225..ad4fd6c0e 100644
--- a/contents/split-operator_method/split-operator_method.md
+++ b/contents/split-operator_method/split-operator_method.md
@@ -103,7 +103,7 @@ Regardless, we first need to set all the initial parameters, including the initi
[import:11-21, lang:"c"](code/c/split_op.c)
[import:52-73, lang:"c"](code/c/split_op.c)
{% sample lang="cpp" %}
-[import:14-49, lang:"cpp"](code/c++/split_op.cpp)
+[import:14-49, lang:"cpp"](code/cpp/split_op.cpp)
{% sample lang="py" %}
[import:11-30, lang:"python"](code/python/split_op.py)
{% sample lang="hs" %}
@@ -126,7 +126,7 @@ Afterwards, we turn them into operators:
[import:23-29, lang:"c"](code/c/split_op.c)
[import:75-96, lang:"c"](code/c/split_op.c)
{% sample lang="cpp" %}
-[import:51-80, lang:"cpp"](code/c++/split_op.cpp)
+[import:51-80, lang:"cpp"](code/cpp/split_op.cpp)
{% sample lang="py" %}
[import:33-54, lang:"python"](code/python/split_op.py)
{% sample lang="hs" %}
@@ -149,7 +149,7 @@ The final step is to do the iteration, itself.
{% sample lang="c" %}
[import:98-148, lang:"c"](code/c/split_op.c)
{% sample lang="cpp" %}
-[import:99-156, lang:"cpp"](code/c++/split_op.cpp)
+[import:99-156, lang:"cpp"](code/cpp/split_op.cpp)
{% sample lang="py" %}
[import:57-95, lang:"python"](code/python/split_op.py)
{% sample lang="hs" %}
@@ -186,7 +186,7 @@ Checking to make sure your code can output the correct energy for a harmonic tra
{% sample lang="c" %}
[import, lang:"c"](code/c/split_op.c)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/split_op.cpp)
+[import, lang:"cpp"](code/cpp/split_op.cpp)
{% sample lang="py" %}
[import:5-127, lang:"python"](code/python/split_op.py)
{% sample lang="hs" %}
diff --git a/contents/stable_marriage_problem/code/c++/stable_marriage.cpp b/contents/stable_marriage_problem/code/cpp/stable_marriage.cpp
similarity index 100%
rename from contents/stable_marriage_problem/code/c++/stable_marriage.cpp
rename to contents/stable_marriage_problem/code/cpp/stable_marriage.cpp
diff --git a/contents/stable_marriage_problem/stable_marriage_problem.md b/contents/stable_marriage_problem/stable_marriage_problem.md
index 3121c6478..2e8850a01 100644
--- a/contents/stable_marriage_problem/stable_marriage_problem.md
+++ b/contents/stable_marriage_problem/stable_marriage_problem.md
@@ -40,7 +40,7 @@ Here is a video describing the stable marriage problem:
{% sample lang="c" %}
[import, lang:"c"](code/c/stable_marriage.c)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/stable_marriage.cpp)
+[import, lang:"cpp"](code/cpp/stable_marriage.cpp)
{% sample lang="js" %}
[import, lang:"javascript"](code/javascript/stable-marriage.js)
{% sample lang="cs" %}
diff --git a/contents/thomas_algorithm/code/c++/thomas.cpp b/contents/thomas_algorithm/code/cpp/thomas.cpp
similarity index 100%
rename from contents/thomas_algorithm/code/c++/thomas.cpp
rename to contents/thomas_algorithm/code/cpp/thomas.cpp
diff --git a/contents/thomas_algorithm/code/golang/thomas.go b/contents/thomas_algorithm/code/go/thomas.go
similarity index 100%
rename from contents/thomas_algorithm/code/golang/thomas.go
rename to contents/thomas_algorithm/code/go/thomas.go
diff --git a/contents/thomas_algorithm/thomas_algorithm.md b/contents/thomas_algorithm/thomas_algorithm.md
index 5af6c3334..81bb47617 100644
--- a/contents/thomas_algorithm/thomas_algorithm.md
+++ b/contents/thomas_algorithm/thomas_algorithm.md
@@ -112,7 +112,7 @@ You will find this algorithm implemented [in this project](https://scratch.mit.e
{% sample lang="hs" %}
[import, lang:"haskell"](code/haskell/thomas.hs)
{% sample lang="go" %}
-[import, lang:"go"](code/golang/thomas.go)
+[import, lang:"go"](code/go/thomas.go)
{% sample lang="v" %}
[import, lang:"v"](code/v/thomas.v)
{% sample lang="swift" %}
@@ -122,7 +122,7 @@ You will find this algorithm implemented [in this project](https://scratch.mit.e
{% sample lang="nim" %}
[import, lang:"nim"](code/nim/thomas_algorithm.nim)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/thomas.cpp)
+[import, lang:"cpp"](code/cpp/thomas.cpp)
{% sample lang="lua" %}
[import, lang:"lua"](code/lua/thomas.lua)
{% sample lang="crystal" %}
diff --git a/contents/tree_traversal/code/c++/tree_example.cpp b/contents/tree_traversal/code/cpp/tree_example.cpp
similarity index 100%
rename from contents/tree_traversal/code/c++/tree_example.cpp
rename to contents/tree_traversal/code/cpp/tree_example.cpp
diff --git a/contents/tree_traversal/code/golang/treetraversal.go b/contents/tree_traversal/code/go/treetraversal.go
similarity index 100%
rename from contents/tree_traversal/code/golang/treetraversal.go
rename to contents/tree_traversal/code/go/treetraversal.go
diff --git a/contents/tree_traversal/tree_traversal.md b/contents/tree_traversal/tree_traversal.md
index 4b6c5b762..5dc6657e0 100644
--- a/contents/tree_traversal/tree_traversal.md
+++ b/contents/tree_traversal/tree_traversal.md
@@ -6,7 +6,7 @@ Trees are naturally recursive data structures, and because of this, we cannot ac
{% sample lang="jl" %}
[import:3-7, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
-[import:12-15, lang:"cpp"](code/c++/tree_example.cpp)
+[import:12-15, lang:"cpp"](code/cpp/tree_example.cpp)
{% sample lang="cs" %}
[import:6-10, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
@@ -35,7 +35,7 @@ As a note, a `node` struct is not necessary in javascript, so this is an example
{% sample lang="st" %}
[import:1-20, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
{% sample lang="go" %}
-[import:5-8, lang:"go"](code/golang/treetraversal.go)
+[import:5-8, lang:"go"](code/go/treetraversal.go)
{% sample lang="asm-x64" %}
[import:24-27, lang:"asm-x64"](code/asm-x64/tree_traversal.s)
{% sample lang="emojic" %}
@@ -54,7 +54,7 @@ Because of this, the most straightforward way to traverse the tree might be recu
{% sample lang="jl" %}
[import:9-16, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
-[import:17-24, lang:"cpp"](code/c++/tree_example.cpp)
+[import:17-24, lang:"cpp"](code/cpp/tree_example.cpp)
{% sample lang="cs" %}
[import:33-44, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
@@ -82,7 +82,7 @@ Because of this, the most straightforward way to traverse the tree might be recu
{% sample lang="st" %}
[import:22-27, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
{% sample lang="go" %}
-[import:10-15, lang:"go"](code/golang/treetraversal.go)
+[import:10-15, lang:"go"](code/go/treetraversal.go)
{% sample lang="asm-x64" %}
[import:290-314, lang:"asm-x64"](code/asm-x64/tree_traversal.s)
{% sample lang="emojic" %}
@@ -110,7 +110,7 @@ Now, in this case the first element searched through is still the root of the tr
{% sample lang="jl" %}
[import:18-26, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
-[import:26-31, lang:"cpp"](code/c++/tree_example.cpp)
+[import:26-31, lang:"cpp"](code/cpp/tree_example.cpp)
{% sample lang="cs" %}
[import:46-57, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
@@ -138,7 +138,7 @@ Now, in this case the first element searched through is still the root of the tr
{% sample lang="st" %}
[import:29-34, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
{% sample lang="go" %}
-[import:17-22, lang:"go"](code/golang/treetraversal.go)
+[import:17-22, lang:"go"](code/go/treetraversal.go)
{% sample lang="asm-x64" %}
[import:316-344, lang:"asm-x64"](code/asm-x64/tree_traversal.s)
{% sample lang="emojic" %}
@@ -161,7 +161,7 @@ In this case, the first node visited is at the bottom of the tree and moves up t
{% sample lang="jl" %}
[import:28-43, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
-[import:34-52 lang:"cpp"](code/c++/tree_example.cpp)
+[import:34-52 lang:"cpp"](code/cpp/tree_example.cpp)
{% sample lang="cs" %}
[import:59-83, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
@@ -189,7 +189,7 @@ In this case, the first node visited is at the bottom of the tree and moves up t
{% sample lang="st" %}
[import:36-49, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
{% sample lang="go" %}
-[import:24-38, lang:"go"](code/golang/treetraversal.go)
+[import:24-38, lang:"go"](code/go/treetraversal.go)
{% sample lang="asm-x64" %}
[import:346-396, lang:"asm-x64"](code/asm-x64/tree_traversal.s)
{% sample lang="emojic" %}
@@ -221,7 +221,7 @@ In code, it looks like this:
{% sample lang="jl" %}
[import:45-56, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
-[import:55-70, lang:"cpp"](code/c++/tree_example.cpp)
+[import:55-70, lang:"cpp"](code/cpp/tree_example.cpp)
{% sample lang="cs" %}
[import:85-98, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
@@ -249,7 +249,7 @@ In code, it looks like this:
{% sample lang="st" %}
[import:47-58, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
{% sample lang="go" %}
-[import:40-49, lang:"go"](code/golang/treetraversal.go)
+[import:40-49, lang:"go"](code/go/treetraversal.go)
{% sample lang="asm-x64" %}
[import:398-445, lang:"asm-x64"](code/asm-x64/tree_traversal.s)
{% sample lang="emojic" %}
@@ -274,7 +274,7 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
{% sample lang="jl" %}
[import:58-69, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
-[import:73-86, lang:"cpp"](code/c++/tree_example.cpp)
+[import:73-86, lang:"cpp"](code/cpp/tree_example.cpp)
{% sample lang="cs" %}
[import:100-113, lang:"csharp"](code/csharp/Tree.cs)
{% sample lang="c" %}
@@ -302,7 +302,7 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
{% sample lang="st" %}
[import:60-71, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
{% sample lang="go" %}
-[import:51-60, lang:"go"](code/golang/treetraversal.go)
+[import:51-60, lang:"go"](code/go/treetraversal.go)
{% sample lang="asm-x64" %}
[import:447-498, lang:"asm-x64"](code/asm-x64/tree_traversal.s)
{% sample lang="emojic" %}
@@ -328,7 +328,7 @@ Here is a video describing tree traversal:
{% sample lang="jl" %}
[import, lang:"julia"](code/julia/Tree.jl)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/tree_example.cpp)
+[import, lang:"cpp"](code/cpp/tree_example.cpp)
{% sample lang="cs" %}
##### Tree.cs
[import, lang:"csharp"](code/csharp/Tree.cs)
@@ -366,7 +366,7 @@ The code snippets were taken from this [Scratch project](https://scratch.mit.edu
{% sample lang="st" %}
[import, lang:"smalltalk"](code/smalltalk/tree_traversal.st)
{% sample lang="go" %}
-[import, lang:"go"](code/golang/treetraversal.go)
+[import, lang:"go"](code/go/treetraversal.go)
{% sample lang="asm-x64" %}
[import, lang:"asm-x64"](code/asm-x64/tree_traversal.s)
{% sample lang="emojic" %}
diff --git a/contents/verlet_integration/code/c++/verlet.cpp b/contents/verlet_integration/code/cpp/verlet.cpp
similarity index 100%
rename from contents/verlet_integration/code/c++/verlet.cpp
rename to contents/verlet_integration/code/cpp/verlet.cpp
diff --git a/contents/verlet_integration/code/golang/verlet.go b/contents/verlet_integration/code/go/verlet.go
similarity index 100%
rename from contents/verlet_integration/code/golang/verlet.go
rename to contents/verlet_integration/code/go/verlet.go
diff --git a/contents/verlet_integration/verlet_integration.md b/contents/verlet_integration/verlet_integration.md
index 08fe4a4b3..80d719bef 100644
--- a/contents/verlet_integration/verlet_integration.md
+++ b/contents/verlet_integration/verlet_integration.md
@@ -33,7 +33,7 @@ Here is what it looks like in code:
{% sample lang="jl" %}
[import:1-13, lang:"julia"](code/julia/verlet.jl)
{% sample lang="cpp" %}
-[import:9-22, lang:"cpp"](code/c++/verlet.cpp)
+[import:9-22, lang:"cpp"](code/cpp/verlet.cpp)
{% sample lang="c" %}
[import:3-14, lang:"c"](code/c/verlet.c)
{% sample lang="java" %}
@@ -53,7 +53,7 @@ Here is what it looks like in code:
{% sample lang="ruby" %}
[import:1-14, lang="ruby"](code/ruby/verlet.rb)
{% sample lang="go" %}
-[import:5-16, lang:"go"](code/golang/verlet.go)
+[import:5-16, lang:"go"](code/go/verlet.go)
{% sample lang="asm-x64" %}
[import:18-42, lang:"asm-x64"](code/asm-x64/verlet.s)
{% sample lang="kotlin" %}
@@ -82,7 +82,7 @@ However, the error for this is $$\mathcal{O}(\Delta t)$$, which is quite poor, b
{% sample lang="jl" %}
[import:15-31, lang:"julia"](code/julia/verlet.jl)
{% sample lang="cpp" %}
-[import:24-41, lang:"cpp"](code/c++/verlet.cpp)
+[import:24-41, lang:"cpp"](code/cpp/verlet.cpp)
{% sample lang="c" %}
[import:16-31, lang:"c"](code/c/verlet.c)
{% sample lang="java" %}
@@ -102,7 +102,7 @@ However, the error for this is $$\mathcal{O}(\Delta t)$$, which is quite poor, b
{% sample lang="ruby" %}
[import:16-32, lang="ruby"](code/ruby/verlet.rb)
{% sample lang="go" %}
-[import:18-30, lang:"go"](code/golang/verlet.go)
+[import:18-30, lang:"go"](code/go/verlet.go)
{% sample lang="asm-x64" %}
[import:44-71, lang:"asm-x64"](code/asm-x64/verlet.s)
{% sample lang="kotlin" %}
@@ -145,7 +145,7 @@ Here is the velocity Verlet method in code:
{% sample lang="jl" %}
[import:33-45, lang:"julia"](code/julia/verlet.jl)
{% sample lang="cpp" %}
-[import:43-54, lang:"cpp"](code/c++/verlet.cpp)
+[import:43-54, lang:"cpp"](code/cpp/verlet.cpp)
{% sample lang="c" %}
[import:33-43, lang:"c"](code/c/verlet.c)
{% sample lang="java" %}
@@ -165,7 +165,7 @@ Here is the velocity Verlet method in code:
{% sample lang="ruby" %}
[import:34-46, lang="ruby"](code/ruby/verlet.rb)
{% sample lang="go" %}
-[import:32-42, lang:"go"](code/golang/verlet.go)
+[import:32-42, lang:"go"](code/go/verlet.go)
{% sample lang="asm-x64" %}
[import:73-101, lang:"asm-x64"](code/asm-x64/verlet.s)
{% sample lang="kotlin" %}
@@ -194,7 +194,7 @@ Both of these methods work simply by iterating timestep-by-timestep and can be w
{% sample lang="jl" %}
[import, lang:"julia"](code/julia/verlet.jl)
{% sample lang="cpp" %}
-[import, lang:"cpp"](code/c++/verlet.cpp)
+[import, lang:"cpp"](code/cpp/verlet.cpp)
{% sample lang="c" %}
[import, lang:"c"](code/c/verlet.c)
{% sample lang="java" %}
@@ -214,7 +214,7 @@ Both of these methods work simply by iterating timestep-by-timestep and can be w
{% sample lang="ruby" %}
[import, lang="ruby"](code/ruby/verlet.rb)
{% sample lang="go" %}
-[import, lang:"go"](code/golang/verlet.go)
+[import, lang:"go"](code/go/verlet.go)
{% sample lang="asm-x64" %}
[import, lang:"asm-x64"](code/asm-x64/verlet.s)
{% sample lang="kotlin" %}
From 4bc3003ab6d53e7c3d08e13e73366f41c60306b4 Mon Sep 17 00:00:00 2001
From: Fabus1184
Date: Sun, 7 Nov 2021 18:09:10 +0100
Subject: [PATCH 068/146] Fixed #917 (#922)
---
contents/euclidean_algorithm/code/lolcode/euclid.lol | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/contents/euclidean_algorithm/code/lolcode/euclid.lol b/contents/euclidean_algorithm/code/lolcode/euclid.lol
index 418851107..28e3230e3 100644
--- a/contents/euclidean_algorithm/code/lolcode/euclid.lol
+++ b/contents/euclidean_algorithm/code/lolcode/euclid.lol
@@ -24,7 +24,7 @@ HAI 1.2
HOW IZ I UKLIDSUP YR NUM1 AN YR NUM2
NUM1 R I IZ ABZ YR NUM1 MKAY
- NUM2 R EI IZ ABZ YR NUM2 MKAY
+ NUM2 R I IZ ABZ YR NUM2 MKAY
IM IN YR LOOP
BOTH SAEM NUM1 AN NUM2, O RLY?
@@ -44,4 +44,4 @@ HAI 1.2
VISIBLE CHECK1
VISIBLE CHECK2
-KTHXBYE
\ No newline at end of file
+KTHXBYE
From be2f97d6c26354b3e2dd58a0d7d2343418c45abd Mon Sep 17 00:00:00 2001
From: James Schloss
Date: Sun, 7 Nov 2021 20:40:30 +0100
Subject: [PATCH 069/146] removing Euler and adjacent chapters (#923)
* removing Euler and adjacent chapters
* Revert "removing Euler and adjacent chapters"
This reverts commit 4293e9d4e66e02b77ac1d18b0212705a5cb7418c.
* just removing chapter from summary
---
SUMMARY.md | 2 --
1 file changed, 2 deletions(-)
diff --git a/SUMMARY.md b/SUMMARY.md
index d76af219d..e41ba39d4 100644
--- a/SUMMARY.md
+++ b/SUMMARY.md
@@ -32,8 +32,6 @@
* [FFT](contents/cooley_tukey/cooley_tukey.md)
* [Decision Problems](contents/decision_problems/decision_problems.md)
* [Stable Marriage Problem](contents/stable_marriage_problem/stable_marriage_problem.md)
-* [Differential Equation Solvers](contents/differential_equations/differential_equations.md)
- * [Forward Euler Method](contents/forward_euler_method/forward_euler_method.md)
* [Physics Solvers](contents/physics_solvers/physics_solvers.md)
* [Verlet Integration](contents/verlet_integration/verlet_integration.md)
* [Quantum Systems](contents/quantum_systems/quantum_systems.md)
From 2529d2322f62283b41f2f155e1fc5c15adfb4497 Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Mon, 8 Nov 2021 04:39:46 +0100
Subject: [PATCH 070/146] Add setup for devcontainer for Piet (#918)
Co-authored-by: Nicholas Tindle
---
.devcontainer/Dockerfile | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 695b0ffbf..4d7e2a736 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -49,8 +49,7 @@ ENV PATH=$PATH:/usr/local/kotlinc/bin
## Use: https://github.com/justinmeza/lci
# Setup Piet
-## Use: https://github.com/boothby/repiet
-
+RUN pip install repiet
# Setup Matlab
# ?????? This is a licensed language???
From d440c5da46bea8e29ff4531349c3e1921c7b16d0 Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Mon, 8 Nov 2021 04:43:59 +0100
Subject: [PATCH 071/146] Add devcontainer setup for lolcode (#916)
Co-authored-by: Nicholas Tindle
---
.devcontainer/Dockerfile | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 4d7e2a736..6e8be7fc6 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -6,7 +6,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
- && apt-get -y install --no-install-recommends build-essential software-properties-common xz-utils g++ sbcl julia python3 python3-pip python3-dev ghc openjdk-11-jdk rustc libssl-dev gfortran libxml2-dev libyaml-dev libgmp-dev libz-dev libncurses5 gnuplot nodejs npm lua5.3 ocaml php ruby-full gnu-smalltalk scratch libfftw3-dev
+ && apt-get -y install --no-install-recommends build-essential software-properties-common xz-utils g++ sbcl julia python3 python3-pip python3-dev ghc openjdk-11-jdk rustc libssl-dev gfortran libxml2-dev libyaml-dev libgmp-dev libz-dev libncurses5 gnuplot nodejs npm lua5.3 ocaml php ruby-full gnu-smalltalk scratch libfftw3-dev cmake
# Setup Crystal
RUN echo 'deb http://download.opensuse.org/repositories/devel:/languages:/crystal/xUbuntu_20.04/ /' | sudo tee /etc/apt/sources.list.d/devel:languages:crystal.list
@@ -46,7 +46,8 @@ RUN unzip /usr/local/kotlinc.zip
ENV PATH=$PATH:/usr/local/kotlinc/bin
# Setup lolcode
-## Use: https://github.com/justinmeza/lci
+RUN git clone https://github.com/justinmeza/lci.git ~/lolcode && cd ~/lolcode && mkdir build && cd build && cmake .. && make -B
+ENV PATH=$PATH:~/lolcode/build
# Setup Piet
RUN pip install repiet
From b115149b8c979ec8ba9482182c0a92b96e31e6ea Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Mon, 8 Nov 2021 06:33:44 +0100
Subject: [PATCH 072/146] Add devcontainer setup for whitespace (#914)
* Add devcontainer setup for VimL/Vim script
* Add devcontainer setup for whitespace
Co-authored-by: Nicholas Tindle
---
.devcontainer/Dockerfile | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index 6e8be7fc6..adb7a8867 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -86,7 +86,8 @@ ENV PATH=$PATH:~/swift/usr/bin
RUN export DEBIAN_FRONTEND=noninteractive && apt-get -y install --no-install-recommends vim
# Setup whitespace
-## ?
+RUN mkdir -p ~/whitespace && git clone https://github.com/wspace/whitespace-haskell ~/whitespace && cd ~/whitespace && make -B
+ENV PATH=$PATH:~/whitespace
# Setup Elm
RUN mkdir -p ~/elm && curl -L -o ~/elm/elm.gz https://github.com/elm/compiler/releases/download/0.19.1/binary-for-linux-64-bit.gz && \
@@ -98,11 +99,11 @@ RUN mkdir -p ~/vlang && wget https://github.com/vlang/v/releases/download/weekly
unzip ~/vlang/vlang.zip -d ~/vlang
ENV PATH=$PATH:~/vlang/v
-# Install the packages that needed extra help
-RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
- && apt-get -y install --no-install-recommends crystal dart nim powershell scala dotnet-sdk-5.0 r-base racket
+# # Install the packages that needed extra help
+# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
+# && apt-get -y install --no-install-recommends crystal dart nim powershell scala dotnet-sdk-5.0 r-base racket
-RUN pip install wheel matplotlib numpy coconut scons
+# RUN pip install wheel matplotlib numpy coconut scons
-RUN sudo sh -c 'npm install -g typescript'
+# RUN sudo sh -c 'npm install -g typescript'
From b0c83073fc6b79b78f3ec58a5b867141f8d519bd Mon Sep 17 00:00:00 2001
From: Nicholas Tindle
Date: Mon, 8 Nov 2021 00:06:05 -0600
Subject: [PATCH 073/146] Fix-devcontainer-commented-out-steps (#925)
* Add devcontainer setup for VimL/Vim script
* Add devcontainer setup for whitespace
* fix commented out dockerfile steps
---
.devcontainer/Dockerfile | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index adb7a8867..c61f5f670 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -99,11 +99,12 @@ RUN mkdir -p ~/vlang && wget https://github.com/vlang/v/releases/download/weekly
unzip ~/vlang/vlang.zip -d ~/vlang
ENV PATH=$PATH:~/vlang/v
-# # Install the packages that needed extra help
-# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
-# && apt-get -y install --no-install-recommends crystal dart nim powershell scala dotnet-sdk-5.0 r-base racket
+# Install the packages that needed extra help
+RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
+ && apt-get -y install --no-install-recommends crystal dart nim powershell scala dotnet-sdk-5.0 r-base racket
+
-# RUN pip install wheel matplotlib numpy coconut scons
+RUN pip install wheel matplotlib numpy coconut scons
-# RUN sudo sh -c 'npm install -g typescript'
+RUN sudo sh -c 'npm install -g typescript'
From 71e7bde8c5213e36cc771c4408cc582c93f94528 Mon Sep 17 00:00:00 2001
From: James Schloss
Date: Mon, 8 Nov 2021 17:52:00 +0200
Subject: [PATCH 074/146] adding a nojekyll file (#926)
---
.nojekyll | 0
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 .nojekyll
diff --git a/.nojekyll b/.nojekyll
new file mode 100644
index 000000000..e69de29bb
From e016f4e77863b75717c2a44b136e34aa3374cfd6 Mon Sep 17 00:00:00 2001
From: PeanutbutterWarrior
<50717143+PeanutbutterWarrior@users.noreply.github.com>
Date: Thu, 11 Nov 2021 15:12:11 +0000
Subject: [PATCH 075/146] Force SCons to use GCC when building .c files (#928)
---
SConstruct | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/SConstruct b/SConstruct
index df000f732..bf9a15979 100644
--- a/SConstruct
+++ b/SConstruct
@@ -8,8 +8,14 @@ Currently, the aim is to provide a way to compile or copy the implementation fil
To run the compilation for all implmeentations in one language, e.g. Rust, run the command `scons build/c`, and the resulting executables will be available in the `cuild/c` directory, each in their respective algorithm directory, containing the executable."""
from pathlib import Path
+import os
-env = Environment()
+env = Environment(ENV={'PATH': os.environ['PATH']})
+
+env['CC'] = 'gcc'
+for tool in ['gcc','gnulink']:
+ env.Tool(tool)
+env['CCFLAGS'] = ''
# Add other languages here when you want to add language targets
languages = ['c']
From edffc2d59e546618d38e2b0ddcb2a3a50a57379e Mon Sep 17 00:00:00 2001
From: PeanutbutterWarrior
<50717143+PeanutbutterWarrior@users.noreply.github.com>
Date: Thu, 11 Nov 2021 22:21:52 +0000
Subject: [PATCH 076/146] Improve SCons to use default files (#931)
---
SConscript | 10 -------
SConstruct | 29 +++++++++++++++++--
contents/IFS/code/c/SConscript | 6 ----
contents/barnsley/code/c/SConscript | 6 ----
contents/computus/code/c/SConscript | 6 ----
.../euclidean_algorithm/code/c/SConscript | 6 ----
contents/flood_fill/code/c/SConscript | 6 ----
.../gaussian_elimination/code/c/SConscript | 6 ----
contents/huffman_encoding/code/c/SConscript | 6 ----
contents/jarvis_march/code/c/SConscript | 6 ----
.../monte_carlo_integration/code/c/SConscript | 6 ----
.../stable_marriage_problem/code/c/SConscript | 6 ----
contents/thomas_algorithm/code/c/SConscript | 6 ----
contents/tree_traversal/code/c/SConscript | 6 ----
contents/verlet_integration/code/c/SConscript | 6 ----
sconscripts/c_SConscript | 6 ++++
16 files changed, 32 insertions(+), 91 deletions(-)
delete mode 100644 SConscript
delete mode 100644 contents/IFS/code/c/SConscript
delete mode 100644 contents/barnsley/code/c/SConscript
delete mode 100644 contents/computus/code/c/SConscript
delete mode 100644 contents/euclidean_algorithm/code/c/SConscript
delete mode 100644 contents/flood_fill/code/c/SConscript
delete mode 100644 contents/gaussian_elimination/code/c/SConscript
delete mode 100644 contents/huffman_encoding/code/c/SConscript
delete mode 100644 contents/jarvis_march/code/c/SConscript
delete mode 100644 contents/monte_carlo_integration/code/c/SConscript
delete mode 100644 contents/stable_marriage_problem/code/c/SConscript
delete mode 100644 contents/thomas_algorithm/code/c/SConscript
delete mode 100644 contents/tree_traversal/code/c/SConscript
delete mode 100644 contents/verlet_integration/code/c/SConscript
create mode 100644 sconscripts/c_SConscript
diff --git a/SConscript b/SConscript
deleted file mode 100644
index be18b33d3..000000000
--- a/SConscript
+++ /dev/null
@@ -1,10 +0,0 @@
-from pathlib import Path
-
-Import('*')
-
-for p in Path('contents').iterdir():
- if (q := (p / 'code')).exists():
- for path in q.iterdir():
- if path.stem in languages:
- env.SConscript(path / 'SConscript', exports='env',
- must_exist=0)
diff --git a/SConstruct b/SConstruct
index bf9a15979..b5f5cdd11 100644
--- a/SConstruct
+++ b/SConstruct
@@ -5,7 +5,7 @@ This provides Builder objects for each of the language implementations in the AA
Currently, the aim is to provide a way to compile or copy the implementation files to the build directory, as well as to provide ways to run them and capture their output.
-To run the compilation for all implmeentations in one language, e.g. Rust, run the command `scons build/c`, and the resulting executables will be available in the `cuild/c` directory, each in their respective algorithm directory, containing the executable."""
+To run the compilation for all implementations in one language, e.g. C, run the command `scons build/c`, and the resulting executables will be available in the `build/c` directory, each in their respective algorithm directory, containing the executable."""
from pathlib import Path
import os
@@ -18,9 +18,32 @@ for tool in ['gcc','gnulink']:
env['CCFLAGS'] = ''
# Add other languages here when you want to add language targets
-languages = ['c']
+# Put 'name_of_language_directory' : 'file_extension'
+languages = {'c': 'c'}
env.C = env.Program
-SConscript('SConscript', exports='env languages')
+Export('env')
+
+sconscripts = []
+files_to_compile = {language: [] for language in languages}
+
+for chapter_dir in Path.cwd().joinpath('contents').iterdir():
+ if (code_dir := (chapter_dir / 'code')).exists():
+ for path in code_dir.iterdir():
+ if path.stem in languages:
+ # Check for overriding sconscript
+ if (sconscript_path := path / 'SConscript').exists():
+ sconscripts.append(sconscript_path)
+ SConscript(sconscript_path, exports='env')
+ else:
+ files_to_compile[path.stem].extend(path.glob(f'*.{languages[path.stem]}'))
+
+sconscript_dir_path = Path('sconscripts')
+for language, files in files_to_compile.items():
+ if files:
+ if (sconscript_path := sconscript_dir_path / f"{language}_SConscript").exists():
+ SConscript(sconscript_path, exports = {'files_to_compile': files})
+ else:
+ print(f'{language} file found at {files[0]}, but no sconscript file is present ')
diff --git a/contents/IFS/code/c/SConscript b/contents/IFS/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/IFS/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/barnsley/code/c/SConscript b/contents/barnsley/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/barnsley/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/computus/code/c/SConscript b/contents/computus/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/computus/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/euclidean_algorithm/code/c/SConscript b/contents/euclidean_algorithm/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/euclidean_algorithm/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/flood_fill/code/c/SConscript b/contents/flood_fill/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/flood_fill/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/gaussian_elimination/code/c/SConscript b/contents/gaussian_elimination/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/gaussian_elimination/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/huffman_encoding/code/c/SConscript b/contents/huffman_encoding/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/huffman_encoding/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/jarvis_march/code/c/SConscript b/contents/jarvis_march/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/jarvis_march/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/monte_carlo_integration/code/c/SConscript b/contents/monte_carlo_integration/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/monte_carlo_integration/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/stable_marriage_problem/code/c/SConscript b/contents/stable_marriage_problem/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/stable_marriage_problem/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/thomas_algorithm/code/c/SConscript b/contents/thomas_algorithm/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/thomas_algorithm/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/tree_traversal/code/c/SConscript b/contents/tree_traversal/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/tree_traversal/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/contents/verlet_integration/code/c/SConscript b/contents/verlet_integration/code/c/SConscript
deleted file mode 100644
index fd696f9ce..000000000
--- a/contents/verlet_integration/code/c/SConscript
+++ /dev/null
@@ -1,6 +0,0 @@
-Import('*')
-from pathlib import Path
-
-dirname = Path.cwd().parents[1].stem
-
-env.C(f'#/build/c/{dirname}', Glob('*.c'))
diff --git a/sconscripts/c_SConscript b/sconscripts/c_SConscript
new file mode 100644
index 000000000..a0cbffd95
--- /dev/null
+++ b/sconscripts/c_SConscript
@@ -0,0 +1,6 @@
+Import('files_to_compile env')
+from pathlib import Path
+
+for file in files_to_compile:
+ chapter_name = file.parent.parent.parent.stem
+ env.C(f'#/build/c/{chapter_name}', str(file))
From a9c5f89c45a5f3fff7bc2567f61dc8402256e2e6 Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Tue, 16 Nov 2021 01:01:15 +0100
Subject: [PATCH 077/146] Fix devcontainer for Kotlin (#930)
---
.devcontainer/Dockerfile | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index c61f5f670..d6ecdfc45 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -40,10 +40,9 @@ ENV PATH=$PATH:~/dlang/dmd-$DLANG_VERSION/linux/bin64/
RUN sudo sh -c 'wget -c https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz -O - | sudo tar -xz -C /usr/local'
ENV PATH=$PATH:/usr/local/go/bin
-# Setup Kotlin (doesnt unzip right maybe?)
-RUN sudo sh -c 'wget -c https://github.com/JetBrains/kotlin/releases/download/v1.5.30/kotlin-compiler-1.5.30.zip -O /usr/local/kotlinc.zip'
-RUN unzip /usr/local/kotlinc.zip
-ENV PATH=$PATH:/usr/local/kotlinc/bin
+# Setup Kotlin
+RUN mkdir -p ~/kotlin && wget -c https://github.com/JetBrains/kotlin/releases/download/v1.5.30/kotlin-compiler-1.5.30.zip -O ~/kotlin/kotlinc.zip && cd ~/kotlin && unzip kotlinc.zip
+ENV PATH=$PATH:~/kotlin/kotlinc/bin
# Setup lolcode
RUN git clone https://github.com/justinmeza/lci.git ~/lolcode && cd ~/lolcode && mkdir build && cd build && cmake .. && make -B
From 41a172891493e779d0f938deaa26be59cab33140 Mon Sep 17 00:00:00 2001
From: Jie
Date: Sun, 21 Nov 2021 23:09:46 +0900
Subject: [PATCH 078/146] [Haskell] Barnsley Fern (#851)
* resolve conflicts
* updates according to review
---
contents/barnsley/barnsley.md | 12 ++++---
contents/barnsley/code/haskell/Barnsley.hs | 40 ++++++++++++++++++++++
2 files changed, 47 insertions(+), 5 deletions(-)
create mode 100644 contents/barnsley/code/haskell/Barnsley.hs
diff --git a/contents/barnsley/barnsley.md b/contents/barnsley/barnsley.md
index c879d7bbd..9c353f8b4 100644
--- a/contents/barnsley/barnsley.md
+++ b/contents/barnsley/barnsley.md
@@ -24,7 +24,7 @@ In this chapter, I hope to provide a slightly more satisfying answer by introduc
| Hutchinson Operator | Attractor |
| ------------------- | --------- |
-| $$\begin{align} f_1(P) &= \begin{bmatrix} 0 &0 \\ 0 &0.16 \end{bmatrix}P + \begin{bmatrix} 0 \\ 0 \end{bmatrix} \\ f_2(P) &= \begin{bmatrix} 0.85 &0.04 \\ -0.04 &0.85 \end{bmatrix}P + \begin{bmatrix} 0 \\ 1.6 \end{bmatrix} \\ f_3(P) &= \begin{bmatrix} 0.2 &-0.26 \\ 0.23 &022 \end{bmatrix}P + \begin{bmatrix} 0 \\ 1.6 \end{bmatrix} \\ f_4(P) &= \begin{bmatrix} -0.15 &0.28 \\ 0.26 &0.24 \end{bmatrix}P + \begin{bmatrix} 0 \\ 0.44 \end{bmatrix} \end{align}$$ | |
+| $$\begin{align} f_1(P) &= \begin{bmatrix} 0 &0 \\ 0 &0.16 \end{bmatrix}P + \begin{bmatrix} 0 \\ 0 \end{bmatrix} \\ f_2(P) &= \begin{bmatrix} 0.85 &0.04 \\ -0.04 &0.85 \end{bmatrix}P + \begin{bmatrix} 0 \\ 1.6 \end{bmatrix} \\ f_3(P) &= \begin{bmatrix} 0.2 &-0.26 \\ 0.23 &0.22 \end{bmatrix}P + \begin{bmatrix} 0 \\ 1.6 \end{bmatrix} \\ f_4(P) &= \begin{bmatrix} -0.15 &0.28 \\ 0.26 &0.24 \end{bmatrix}P + \begin{bmatrix} 0 \\ 0.44 \end{bmatrix} \end{align}$$ | |
At first glance, this set of functions looks like an incomprehensible mess of magic numbers to create a specific result, and in a sense, that is precisely correct.
That said, we will go through each function and explain how it works, while also providing a simple chaos game implementation in code.
@@ -54,7 +54,7 @@ Now let's hop into disecting the Barnsley fern by seeing how each transform affe
| -------- | --------- |
| $$f_1(P) = \begin{bmatrix} 0 &0 \\ 0 &0.16 \end{bmatrix}P + \begin{bmatrix} 0 \\ 0 \end{bmatrix}$$
This operation moves every point to a single line. |
This operation flips every point and rotates to the right.|
|
At this stage, it *might* be clear what is going on, but it's not exactly obvious.
@@ -71,7 +71,7 @@ The easiest way to make sense of this is to show the operations on the Barnsley
| -------- | --------- |
| $$f_1(P) = \begin{bmatrix} 0 &0 \\ 0 &0.16 \end{bmatrix}P + \begin{bmatrix} 0 \\ 0 \end{bmatrix}$$ |
|
As an important note: the idea of modifying a resulting image by twiddling the knobs of an affine transform is the heart of many interesting methods, including fractal image compression where a low resolution version of an image is stored along with a reconstructing function set to generate high-quality images on-the-fly {{ "fractal-compression" | cite }}{{ "saupe1994review" | cite }}.
@@ -135,6 +135,8 @@ The biggest differences between the two code implementations is that the Barnsle
[import, lang:"java"](code/java/Barnsley.java)
{% sample lang="coco" %}
[import, lang:"coconut"](code/coconut/barnsley.coco)
+{% sample lang="hs" %}
+[import, lang:"haskell"](code/haskell/Barnsley.hs)
{% endmethod %}
### Bibliography
diff --git a/contents/barnsley/code/haskell/Barnsley.hs b/contents/barnsley/code/haskell/Barnsley.hs
new file mode 100644
index 000000000..bf7024200
--- /dev/null
+++ b/contents/barnsley/code/haskell/Barnsley.hs
@@ -0,0 +1,40 @@
+import Data.Array (Array, bounds, elems, listArray, (!))
+import Data.List (intercalate)
+import System.Random
+
+data Point = Point Double Double
+
+chaosGame :: RandomGen g => g -> Int -> Array Int (Double, (Point -> Point)) -> [Point]
+chaosGame g n hutchinson = take n points
+ where
+ (x, g') = random g
+ (y, g'') = random g'
+
+ cumulProbabilities = scanl1 (+) $ map fst $ elems hutchinson
+ to_choice x = length $ takeWhile (x >) cumulProbabilities
+
+ picks = map to_choice $ randomRs (0, 1) g''
+ step = fmap snd hutchinson
+
+ points = Point x y : zipWith (step !) picks points
+
+affine :: (Double, Double, Double, Double) -> (Double, Double) -> Point -> Point
+affine (xx, xy, yx, yy) (a, b) (Point x y) = Point (a + xx * x + xy * y) (b + yx * x + yy * y)
+
+showPoint :: Point -> String
+showPoint (Point x y) = show x ++ "\t" ++ show y
+
+main :: IO ()
+main = do
+ g <- newStdGen
+ let barnsley =
+ listArray
+ (0, 3)
+ [ (0.01, affine (0, 0, 0, 0.16) (0, 0)),
+ (0.85, affine (0.85, 0.04, -0.04, 0.85) (0, 1.6)),
+ (0.07, affine (0.2, -0.26, 0.23, 0.22) (0, 1.6)),
+ (0.07, affine (-0.15, 0.28, 0.26, 0.24) (0, 0.44))
+ ]
+ points = chaosGame g 100000 barnsley
+
+ writeFile "out.dat" $ intercalate "\n" $ map showPoint points
From 866581ecc7a46a2e235e2e9e42db89046bcd4385 Mon Sep 17 00:00:00 2001
From: Nicholas Tindle
Date: Mon, 22 Nov 2021 10:29:01 -0600
Subject: [PATCH 079/146] feat: add publish dockerfile (#938)
---
.devcontainer/devcontainer.json | 2 +-
.github/workflows/publish_container.yml | 17 +++++++++++++++++
.devcontainer/Dockerfile => Dockerfile | 0
3 files changed, 18 insertions(+), 1 deletion(-)
create mode 100644 .github/workflows/publish_container.yml
rename .devcontainer/Dockerfile => Dockerfile (100%)
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index d09155c0b..e9d6bbefa 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -3,7 +3,7 @@
{
"name": "Ubuntu",
"build": {
- "dockerfile": "Dockerfile",
+ "dockerfile": "../Dockerfile",
// Update 'VARIANT' to pick an Ubuntu version: focal, bionic
"args": { "VARIANT": "focal" }
},
diff --git a/.github/workflows/publish_container.yml b/.github/workflows/publish_container.yml
new file mode 100644
index 000000000..84759dbdf
--- /dev/null
+++ b/.github/workflows/publish_container.yml
@@ -0,0 +1,17 @@
+name: Publish Docker
+on:
+ push:
+ branches:
+ - master
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@master
+ - name: Publish to Registry
+ uses: elgohr/Publish-Docker-Github-Action@master
+ with:
+ name: algorithm-archivists/aaa-langs
+ username: ${{ github.actor }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+ registry: ghcr.io
\ No newline at end of file
diff --git a/.devcontainer/Dockerfile b/Dockerfile
similarity index 100%
rename from .devcontainer/Dockerfile
rename to Dockerfile
From 465e1e859ee9351209ae1a8f611492614a6918a2 Mon Sep 17 00:00:00 2001
From: Sammy Plat
Date: Mon, 22 Nov 2021 19:07:28 +0100
Subject: [PATCH 080/146] Added C++ compilation (#939)
---
SConstruct | 5 ++++-
contents/split-operator_method/code/cpp/SConscript | 6 ++++++
sconscripts/cpp_SConscript | 6 ++++++
3 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 contents/split-operator_method/code/cpp/SConscript
create mode 100644 sconscripts/cpp_SConscript
diff --git a/SConstruct b/SConstruct
index b5f5cdd11..c93744156 100644
--- a/SConstruct
+++ b/SConstruct
@@ -16,12 +16,15 @@ env['CC'] = 'gcc'
for tool in ['gcc','gnulink']:
env.Tool(tool)
env['CCFLAGS'] = ''
+env['CXXFLAGS'] = '-std=c++17'
# Add other languages here when you want to add language targets
# Put 'name_of_language_directory' : 'file_extension'
-languages = {'c': 'c'}
+languages = {'c': 'c', 'cpp': 'cpp'}
env.C = env.Program
+env.CPlusPlus = env.Program
+
Export('env')
diff --git a/contents/split-operator_method/code/cpp/SConscript b/contents/split-operator_method/code/cpp/SConscript
new file mode 100644
index 000000000..a25ed8c91
--- /dev/null
+++ b/contents/split-operator_method/code/cpp/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.CPlusPlus(f'#/build/cpp/{dirname}', Glob('*.cpp'), LIBS=['m', 'fftw3'])
diff --git a/sconscripts/cpp_SConscript b/sconscripts/cpp_SConscript
new file mode 100644
index 000000000..a30e08652
--- /dev/null
+++ b/sconscripts/cpp_SConscript
@@ -0,0 +1,6 @@
+Import('files_to_compile env')
+from pathlib import Path
+
+for file in files_to_compile:
+ chapter_name = file.parent.parent.parent.stem
+ env.CPlusPlus(f'#/build/cpp/{chapter_name}', str(file))
From edbf50bfaeba82f84aa14f51cd26ef0d29dbd32b Mon Sep 17 00:00:00 2001
From: James Schloss
Date: Mon, 22 Nov 2021 19:16:35 +0100
Subject: [PATCH 081/146] attempt at output standardization for approximate
counting (#913)
* attempt at output standardization for approximate counting
* further standardization
---
.../code/c/approximate_counting.c | 15 +++++++----
.../code/cpp/approximate_counting.cpp | 10 +++----
.../code/julia/approximate_counting.jl | 26 ++++++++++++-------
.../code/python/approximate_counting.py | 9 ++++---
4 files changed, 37 insertions(+), 23 deletions(-)
diff --git a/contents/approximate_counting/code/c/approximate_counting.c b/contents/approximate_counting/code/c/approximate_counting.c
index da44334a7..2be6ffaf8 100644
--- a/contents/approximate_counting/code/c/approximate_counting.c
+++ b/contents/approximate_counting/code/c/approximate_counting.c
@@ -63,19 +63,24 @@ void test_approximation_count(size_t n_trials, size_t n_items, double a,
}
double avg = sum / n_trials;
- assert(fabs((avg - n_items) / n_items) < threshold);
+ if (fabs((avg - n_items) / n_items) < threshold){
+ printf("passed\n");
+ }
+ else{
+ printf("failed\n");
+ }
}
int main()
{
srand(time(NULL));
- printf("Counting Tests, 100 trials\n");
- printf("testing 1000, a = 30, 10%% error\n");
+ printf("[#]\nCounting Tests, 100 trials\n");
+ printf("[#]\ntesting 1,000, a = 30, 10%% error\n");
test_approximation_count(100, 1000, 30, 0.1);
- printf("testing 12345, a = 10, 10%% error\n");
+ printf("[#]\ntesting 12,345, a = 10, 10%% error\n");
test_approximation_count(100, 12345, 10, 0.1);
- printf("testing 222222, a = 0.5, 20%% error\n");
+ printf("[#]\ntesting 222,222, a = 0.5, 20%% error\n");
test_approximation_count(100, 222222, 0.5, 0.2);
return 0;
diff --git a/contents/approximate_counting/code/cpp/approximate_counting.cpp b/contents/approximate_counting/code/cpp/approximate_counting.cpp
index 53f4641af..1ee2790b7 100644
--- a/contents/approximate_counting/code/cpp/approximate_counting.cpp
+++ b/contents/approximate_counting/code/cpp/approximate_counting.cpp
@@ -55,17 +55,17 @@ auto test_approximate_count(
for (auto i = 0; i < n_trials; ++i)
sum += approximate_count(n_items, a);
const auto avg = sum / n_trials;
- return std::abs((avg - n_items) / n_items) < threshold ? "pass" : "fail";
+ return std::abs((avg - n_items) / n_items) < threshold ? "passed" : "failed";
}
int main() {
- std::cout << "Counting Tests, 100 trials\n";
+ std::cout << "[#]\nCounting Tests, 100 trials\n";
- std::cout << "testing 1,000, a = 30, 10% error "
+ std::cout << "[#]\ntesting 1,000, a = 30, 10% error \n"
<< test_approximate_count(100, 1000, 30, 0.1) << "\n";
- std::cout << "testing 12,345, a = 10, 10% error "
+ std::cout << "[#]\ntesting 12,345, a = 10, 10% error \n"
<< test_approximate_count(100, 12345, 10, 0.1) << "\n";
// Note : with a lower a, we need more trials, so a higher % error here.
- std::cout << "testing 222,222, a = 0.5, 20% error "
+ std::cout << "[#]\ntesting 222,222, a = 0.5, 20% error \n"
<< test_approximate_count(100, 222222, 0.5, 0.2) << "\n";
}
diff --git a/contents/approximate_counting/code/julia/approximate_counting.jl b/contents/approximate_counting/code/julia/approximate_counting.jl
index c6cf3b223..24c9f0fb6 100644
--- a/contents/approximate_counting/code/julia/approximate_counting.jl
+++ b/contents/approximate_counting/code/julia/approximate_counting.jl
@@ -47,15 +47,21 @@ function test_approximate_count(n_trials, n_items, a, threshold)
avg = sum(samples)/n_trials
- @test (abs((avg - n_items) / n_items) < threshold)
+ if (abs((avg - n_items) / n_items) < threshold)
+ println("passed")
+ else
+ println("failed")
+ end
end
-@testset "Counting Tests, 100 trials" begin
- println("testing 1,000, a = 30, 10% error")
- test_approximate_count(100, 1000, 30, 0.1)
- println("testing 12,345, a = 10, 10% error")
- test_approximate_count(100, 12345, 10, 0.1)
- # Note: with a lower a, we need more trials, so a higher % error here.
- println("testing 222,222, a = 0.5, 20% error")
- test_approximate_count(100, 222222, 0.5, 0.2)
-end
+println("[#]\nCounting Tests, 100 trials")
+
+println("[#]\ntesting 1,000, a = 30, 10% error")
+test_approximate_count(100, 1000, 30, 0.1)
+
+println("[#]\ntesting 12,345, a = 10, 10% error")
+test_approximate_count(100, 12345, 10, 0.1)
+
+# Note: with a lower a, we need more trials, so a higher % error here.
+println("[#]\ntesting 222,222, a = 0.5, 20% error")
+test_approximate_count(100, 222222, 0.5, 0.2)
diff --git a/contents/approximate_counting/code/python/approximate_counting.py b/contents/approximate_counting/code/python/approximate_counting.py
index 0088debcc..a8381ffe8 100644
--- a/contents/approximate_counting/code/python/approximate_counting.py
+++ b/contents/approximate_counting/code/python/approximate_counting.py
@@ -40,10 +40,13 @@ def test_approximate_count(n_trials, n_items, a, threshold):
if abs((avg - n_items)/n_items) < threshold:
print("passed")
+ else:
+ print("failed")
-print("testing 1,000, a = 30, 10% error")
+print("[#]\nCounting Tests, 100 trials")
+print("[#]\ntesting 1,000, a = 30, 10% error")
test_approximate_count(100, 1000, 30, 0.1)
-print("testing 12,345, a = 10, 10% error")
+print("[#]\ntesting 12,345, a = 10, 10% error")
test_approximate_count(100, 12345, 10, 0.1)
-print("testing 222,222, a = 0.5, 20% error")
+print("[#]\ntesting 222,222, a = 0.5, 20% error")
test_approximate_count(100, 222222, 0.5, 0.2)
From 9d9e1cb232a9165573773fd1dd6baa9455c38302 Mon Sep 17 00:00:00 2001
From: Sammy Plat
Date: Sun, 28 Nov 2021 15:35:30 +0100
Subject: [PATCH 082/146] Added x64 assembly compilation (#940)
---
SConstruct | 15 ++++++++-------
contents/cooley_tukey/code/asm-x64/SConscript | 6 ++++++
.../forward_euler_method/code/asm-x64/SConscript | 6 ++++++
sconscripts/asm-x64_SConscript | 6 ++++++
4 files changed, 26 insertions(+), 7 deletions(-)
create mode 100644 contents/cooley_tukey/code/asm-x64/SConscript
create mode 100644 contents/forward_euler_method/code/asm-x64/SConscript
create mode 100644 sconscripts/asm-x64_SConscript
diff --git a/SConstruct b/SConstruct
index c93744156..93354e152 100644
--- a/SConstruct
+++ b/SConstruct
@@ -10,21 +10,21 @@ To run the compilation for all implementations in one language, e.g. C, run the
from pathlib import Path
import os
-env = Environment(ENV={'PATH': os.environ['PATH']})
+env = Environment(ENV={'PATH': os.environ['PATH']},
+ tools=['gcc', 'gnulink', 'g++', 'gas'])
+
+env['ASFLAGS'] = '--64'
-env['CC'] = 'gcc'
-for tool in ['gcc','gnulink']:
- env.Tool(tool)
env['CCFLAGS'] = ''
env['CXXFLAGS'] = '-std=c++17'
# Add other languages here when you want to add language targets
# Put 'name_of_language_directory' : 'file_extension'
-languages = {'c': 'c', 'cpp': 'cpp'}
+languages = {'c': 'c', 'cpp': 'cpp', 'asm-x64': 's'}
env.C = env.Program
env.CPlusPlus = env.Program
-
+env.X64 = env.Program
Export('env')
@@ -46,7 +46,8 @@ sconscript_dir_path = Path('sconscripts')
for language, files in files_to_compile.items():
if files:
if (sconscript_path := sconscript_dir_path / f"{language}_SConscript").exists():
- SConscript(sconscript_path, exports = {'files_to_compile': files})
+ SConscript(sconscript_path, exports = {'files_to_compile': files,
+ 'language': language})
else:
print(f'{language} file found at {files[0]}, but no sconscript file is present ')
diff --git a/contents/cooley_tukey/code/asm-x64/SConscript b/contents/cooley_tukey/code/asm-x64/SConscript
new file mode 100644
index 000000000..05360fe6c
--- /dev/null
+++ b/contents/cooley_tukey/code/asm-x64/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.X64(f'#/build/asm-x64/{dirname}', Glob('*.s'), LIBS=['m'], LINKFLAGS='-no-pie')
diff --git a/contents/forward_euler_method/code/asm-x64/SConscript b/contents/forward_euler_method/code/asm-x64/SConscript
new file mode 100644
index 000000000..9322fd10c
--- /dev/null
+++ b/contents/forward_euler_method/code/asm-x64/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.X64(f'#/build/asm-x64/{dirname}', Glob('*.s'), LIBS='m', LINKFLAGS='-no-pie')
diff --git a/sconscripts/asm-x64_SConscript b/sconscripts/asm-x64_SConscript
new file mode 100644
index 000000000..caabf226f
--- /dev/null
+++ b/sconscripts/asm-x64_SConscript
@@ -0,0 +1,6 @@
+Import('files_to_compile language env')
+from pathlib import Path
+
+for file in files_to_compile:
+ chapter_name = file.parent.parent.parent.stem
+ env.X64(f'#/build/{language}/{chapter_name}', str(file), LINKFLAGS='-no-pie')
From 18eebd6277158738b1ef507037939a50749b8a70 Mon Sep 17 00:00:00 2001
From: PeanutbutterWarrior
<50717143+PeanutbutterWarrior@users.noreply.github.com>
Date: Sun, 28 Nov 2021 20:56:17 +0000
Subject: [PATCH 083/146] Add Rust to SCons (#945)
* Add rust builder and build script
* Move file to be discovered by SCons, and update Cargo.toml to reflect this
* Add rustc to SCons
* Add Cargo.toml files for code requiring libraries
* Add cargo building when Cargo.toml is present
* Fix copying fail on linux due to directory name and file name collision
* Add build artifacts to SCons clean command and .gitignore
* Fix Not a directory issue due to getting parent directory of a file
* Remove redefinition of languages dictionary
* Add rustc and cargo install to docker
* Update Cooley-Tukey to use correct version of crates
* Update split-operator method to use correct library versions and apply fixes from #688
---
.gitignore | 4 ++++
Dockerfile | 5 ++++-
SConstruct | 13 +++++++++----
contents/barnsley/code/rust/Cargo.toml | 8 ++++++--
.../code/rust/{src/main.rs => barnsley.rs} | 0
contents/cooley_tukey/code/rust/Cargo.toml | 14 ++++++++++++++
contents/huffman_encoding/code/rust/Cargo.toml | 13 +++++++++++++
.../monte_carlo_integration/code/rust/Cargo.toml | 13 +++++++++++++
.../split-operator_method/code/rust/Cargo.toml | 13 +++++++++++++
.../split-operator_method/code/rust/split_op.rs | 5 ++---
sconscripts/rust_SConscript | 14 ++++++++++++++
11 files changed, 92 insertions(+), 10 deletions(-)
rename contents/barnsley/code/rust/{src/main.rs => barnsley.rs} (100%)
create mode 100644 contents/cooley_tukey/code/rust/Cargo.toml
create mode 100644 contents/huffman_encoding/code/rust/Cargo.toml
create mode 100644 contents/monte_carlo_integration/code/rust/Cargo.toml
create mode 100644 contents/split-operator_method/code/rust/Cargo.toml
create mode 100644 sconscripts/rust_SConscript
diff --git a/.gitignore b/.gitignore
index 231da8ea1..4d5a431b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -524,3 +524,7 @@ vscode/
# SCons build directory
build/
+
+# Cargo artifacts
+Cargo.lock
+target/
diff --git a/Dockerfile b/Dockerfile
index d6ecdfc45..a0808c1ef 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -6,7 +6,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
- && apt-get -y install --no-install-recommends build-essential software-properties-common xz-utils g++ sbcl julia python3 python3-pip python3-dev ghc openjdk-11-jdk rustc libssl-dev gfortran libxml2-dev libyaml-dev libgmp-dev libz-dev libncurses5 gnuplot nodejs npm lua5.3 ocaml php ruby-full gnu-smalltalk scratch libfftw3-dev cmake
+ && apt-get -y install --no-install-recommends build-essential software-properties-common xz-utils g++ sbcl julia python3 python3-pip python3-dev ghc openjdk-11-jdk libssl-dev gfortran libxml2-dev libyaml-dev libgmp-dev libz-dev libncurses5 gnuplot nodejs npm lua5.3 ocaml php ruby-full gnu-smalltalk scratch libfftw3-dev cmake
# Setup Crystal
RUN echo 'deb http://download.opensuse.org/repositories/devel:/languages:/crystal/xUbuntu_20.04/ /' | sudo tee /etc/apt/sources.list.d/devel:languages:crystal.list
@@ -72,6 +72,9 @@ RUN sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu fo
RUN sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D9D33FCD84D82C17288BA03B3C9A6980F827E01E
RUN sudo add-apt-repository 'deb http://ppa.launchpad.net/plt/racket/ubuntu focal main'
+# Setup Rust
+RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
+
# Setup Scratch
## using 1.x right now.... in future checkout snap or adobe air?
diff --git a/SConstruct b/SConstruct
index 93354e152..1a20bf633 100644
--- a/SConstruct
+++ b/SConstruct
@@ -10,17 +10,22 @@ To run the compilation for all implementations in one language, e.g. C, run the
from pathlib import Path
import os
-env = Environment(ENV={'PATH': os.environ['PATH']},
- tools=['gcc', 'gnulink', 'g++', 'gas'])
+rust_cargo_builder = Builder(action=['cargo build --bins --manifest-path $MANIFEST',
+ Move('$TARGET$PROGSUFFIX', '$SOURCE_DIR/target/debug/main$PROGSUFFIX')])
-env['ASFLAGS'] = '--64'
+rust_rustc_builder = Builder(action='rustc $SOURCE -o $TARGET$PROGSUFFIX')
+
+env = Environment(ENV=os.environ,
+ BUILDERS={'rustc': rust_rustc_builder, 'cargo': rust_cargo_builder},
+ tools=['gcc', 'gnulink', 'g++', 'gas'])
env['CCFLAGS'] = ''
env['CXXFLAGS'] = '-std=c++17'
+env['ASFLAGS'] = '--64'
# Add other languages here when you want to add language targets
# Put 'name_of_language_directory' : 'file_extension'
-languages = {'c': 'c', 'cpp': 'cpp', 'asm-x64': 's'}
+languages = {'c': 'c', 'cpp': 'cpp', 'asm-x64': 's', 'rust': 'rs'}
env.C = env.Program
env.CPlusPlus = env.Program
diff --git a/contents/barnsley/code/rust/Cargo.toml b/contents/barnsley/code/rust/Cargo.toml
index 40780594a..52505634b 100644
--- a/contents/barnsley/code/rust/Cargo.toml
+++ b/contents/barnsley/code/rust/Cargo.toml
@@ -1,9 +1,13 @@
[package]
-name = "rust"
+name = "barnsley"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
-rand = "0.8.4"
\ No newline at end of file
+rand = "0.8.4"
+
+[[bin]]
+path = "./barnsley.rs"
+name = "main"
\ No newline at end of file
diff --git a/contents/barnsley/code/rust/src/main.rs b/contents/barnsley/code/rust/barnsley.rs
similarity index 100%
rename from contents/barnsley/code/rust/src/main.rs
rename to contents/barnsley/code/rust/barnsley.rs
diff --git a/contents/cooley_tukey/code/rust/Cargo.toml b/contents/cooley_tukey/code/rust/Cargo.toml
new file mode 100644
index 000000000..0cba5179d
--- /dev/null
+++ b/contents/cooley_tukey/code/rust/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "rust"
+version = "0.1.0"
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+rand = "0.7.3"
+rustfft = "4.1.0"
+
+[[bin]]
+path = "./fft.rs"
+name = "main"
\ No newline at end of file
diff --git a/contents/huffman_encoding/code/rust/Cargo.toml b/contents/huffman_encoding/code/rust/Cargo.toml
new file mode 100644
index 000000000..1add99ad2
--- /dev/null
+++ b/contents/huffman_encoding/code/rust/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "huffman"
+version = "0.1.0"
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+itertools = "0.10.1"
+
+[[bin]]
+path = "./huffman.rs"
+name = "main"
\ No newline at end of file
diff --git a/contents/monte_carlo_integration/code/rust/Cargo.toml b/contents/monte_carlo_integration/code/rust/Cargo.toml
new file mode 100644
index 000000000..17ff7f385
--- /dev/null
+++ b/contents/monte_carlo_integration/code/rust/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "montecarlo"
+version = "0.1.0"
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+rand = "0.8.4"
+
+[[bin]]
+path = "./monte_carlo.rs"
+name = "main"
\ No newline at end of file
diff --git a/contents/split-operator_method/code/rust/Cargo.toml b/contents/split-operator_method/code/rust/Cargo.toml
new file mode 100644
index 000000000..def85c23e
--- /dev/null
+++ b/contents/split-operator_method/code/rust/Cargo.toml
@@ -0,0 +1,13 @@
+[package]
+name = "splitop"
+version = "0.1.0"
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
+rustfft = "4.1.0"
+
+[[bin]]
+path = "./split_op.rs"
+name = "main"
\ No newline at end of file
diff --git a/contents/split-operator_method/code/rust/split_op.rs b/contents/split-operator_method/code/rust/split_op.rs
index 7269f5148..d29e16a2e 100644
--- a/contents/split-operator_method/code/rust/split_op.rs
+++ b/contents/split-operator_method/code/rust/split_op.rs
@@ -1,7 +1,6 @@
-extern crate num;
extern crate rustfft;
-use num::complex::Complex;
+use rustfft::num_complex::Complex;
use rustfft::FFTplanner;
use std::f64::consts::PI;
use std::fs::File;
@@ -95,7 +94,7 @@ fn fft(x: &mut Vec>, inverse: bool) {
let mut y = vec![Complex::new(0.0_f64, 0.0_f64); x.len()];
let mut p = FFTplanner::new(inverse);
let fft = p.plan_fft(x.len());
- fft.process(x, &mut y);
+ fft.process(x.as_mut_slice(), y.as_mut_slice());
for i in 0..x.len() {
x[i] = y[i] / (x.len() as f64).sqrt();
diff --git a/sconscripts/rust_SConscript b/sconscripts/rust_SConscript
new file mode 100644
index 000000000..b9cf669c7
--- /dev/null
+++ b/sconscripts/rust_SConscript
@@ -0,0 +1,14 @@
+Import('files_to_compile env')
+from pathlib import Path
+
+for file in files_to_compile:
+ chapter_name = file.parent.parent.parent.stem
+ if (file.parent / 'Cargo.toml').exists():
+ env.cargo(target=f'#/build/rust/{chapter_name}',
+ source=str(file),
+ MANIFEST=str(file.parent / 'Cargo.toml'),
+ SOURCE_DIR=str(file.parent))
+ env.Clean('rust', str(file.parent / 'target'))
+ else:
+ env.rustc(f'#/build/rust/{chapter_name}', str(file))
+ env.Clean('rust', f'#/build/rust/{chapter_name}.pdb')
From c3c0938dd13b4f8b583ec7179b3d1d49dec5d789 Mon Sep 17 00:00:00 2001
From: PeanutbutterWarrior
<50717143+PeanutbutterWarrior@users.noreply.github.com>
Date: Sun, 28 Nov 2021 22:19:04 +0000
Subject: [PATCH 084/146] Add Go to SCons (#947)
---
SConstruct | 8 ++++++--
sconscripts/go_SConscript | 6 ++++++
2 files changed, 12 insertions(+), 2 deletions(-)
create mode 100644 sconscripts/go_SConscript
diff --git a/SConstruct b/SConstruct
index 1a20bf633..8f01fe4fe 100644
--- a/SConstruct
+++ b/SConstruct
@@ -15,8 +15,12 @@ rust_cargo_builder = Builder(action=['cargo build --bins --manifest-path $MANIFE
rust_rustc_builder = Builder(action='rustc $SOURCE -o $TARGET$PROGSUFFIX')
+go_builder = Builder(action='go build -o $TARGET$PROGSUFFIX $SOURCE')
+
env = Environment(ENV=os.environ,
- BUILDERS={'rustc': rust_rustc_builder, 'cargo': rust_cargo_builder},
+ BUILDERS={'rustc': rust_rustc_builder,
+ 'cargo': rust_cargo_builder,
+ 'Go': go_builder},
tools=['gcc', 'gnulink', 'g++', 'gas'])
env['CCFLAGS'] = ''
@@ -25,7 +29,7 @@ env['ASFLAGS'] = '--64'
# Add other languages here when you want to add language targets
# Put 'name_of_language_directory' : 'file_extension'
-languages = {'c': 'c', 'cpp': 'cpp', 'asm-x64': 's', 'rust': 'rs'}
+languages = {'c': 'c', 'cpp': 'cpp', 'asm-x64': 's', 'rust': 'rs', 'go': 'go'}
env.C = env.Program
env.CPlusPlus = env.Program
diff --git a/sconscripts/go_SConscript b/sconscripts/go_SConscript
new file mode 100644
index 000000000..795be1d53
--- /dev/null
+++ b/sconscripts/go_SConscript
@@ -0,0 +1,6 @@
+Import('files_to_compile env')
+from pathlib import Path
+
+for file in files_to_compile:
+ chapter_name = file.parent.parent.parent.stem
+ env.Go(f'#/build/go/{chapter_name}', str(file))
From 0aa53332fb7366a7a1b9f93f55d7c72126534088 Mon Sep 17 00:00:00 2001
From: Sammy Plat
Date: Sun, 28 Nov 2021 23:36:08 +0100
Subject: [PATCH 085/146] Added Fortran compilation (#948)
* Added Fortran compilation
* Corrected a typo
---
SConstruct | 12 ++++++++++--
contents/euclidean_algorithm/code/fortran/SConscript | 6 ++++++
sconscripts/fortran_SConscript | 6 ++++++
3 files changed, 22 insertions(+), 2 deletions(-)
create mode 100644 contents/euclidean_algorithm/code/fortran/SConscript
create mode 100644 sconscripts/fortran_SConscript
diff --git a/SConstruct b/SConstruct
index 8f01fe4fe..222ae14c0 100644
--- a/SConstruct
+++ b/SConstruct
@@ -21,7 +21,7 @@ env = Environment(ENV=os.environ,
BUILDERS={'rustc': rust_rustc_builder,
'cargo': rust_cargo_builder,
'Go': go_builder},
- tools=['gcc', 'gnulink', 'g++', 'gas'])
+ tools=['gcc', 'gnulink', 'g++', 'gas', 'gfortran'])
env['CCFLAGS'] = ''
env['CXXFLAGS'] = '-std=c++17'
@@ -29,11 +29,19 @@ env['ASFLAGS'] = '--64'
# Add other languages here when you want to add language targets
# Put 'name_of_language_directory' : 'file_extension'
-languages = {'c': 'c', 'cpp': 'cpp', 'asm-x64': 's', 'rust': 'rs', 'go': 'go'}
+languages = {
+ 'c': 'c',
+ 'cpp': 'cpp',
+ 'asm-x64': 's',
+ 'rust': 'rs',
+ 'go': 'go',
+ 'fortran': 'f90',
+}
env.C = env.Program
env.CPlusPlus = env.Program
env.X64 = env.Program
+env.Fortran = env.Program
Export('env')
diff --git a/contents/euclidean_algorithm/code/fortran/SConscript b/contents/euclidean_algorithm/code/fortran/SConscript
new file mode 100644
index 000000000..8146feee9
--- /dev/null
+++ b/contents/euclidean_algorithm/code/fortran/SConscript
@@ -0,0 +1,6 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.Fortran(f'#/build/fortran/{dirname}', 'euclidean.f90')
diff --git a/sconscripts/fortran_SConscript b/sconscripts/fortran_SConscript
new file mode 100644
index 000000000..df3e7fc27
--- /dev/null
+++ b/sconscripts/fortran_SConscript
@@ -0,0 +1,6 @@
+Import('files_to_compile env')
+from pathlib import Path
+
+for file in files_to_compile:
+ chapter_name = file.parent.parent.parent.stem
+ env.Fortran(f'#/build/fortran/{chapter_name}', str(file))
From 71e27baca21fe5d42787c37d76763f4060ac34fb Mon Sep 17 00:00:00 2001
From: Sammy Plat
Date: Mon, 29 Nov 2021 23:12:09 +0100
Subject: [PATCH 086/146] Fixing C warnings (#934)
* Added warnings as errors for C/C++ code and fixed C warnings.
---
SConstruct | 2 +-
contents/IFS/code/c/IFS.c | 2 +-
contents/barnsley/code/c/barnsley.c | 1 +
contents/cooley_tukey/code/c/fft.c | 8 ++--
.../code/c/euclidean_example.c | 48 +++++++++----------
contents/flood_fill/code/c/flood_fill.c | 8 ++--
.../code/c/gaussian_elimination.c | 20 ++++----
contents/huffman_encoding/code/c/huffman.c | 4 +-
.../split-operator_method/code/c/split_op.c | 6 +--
.../code/c/stable_marriage.c | 9 ++--
10 files changed, 54 insertions(+), 54 deletions(-)
diff --git a/SConstruct b/SConstruct
index 222ae14c0..bd851cf0a 100644
--- a/SConstruct
+++ b/SConstruct
@@ -23,7 +23,7 @@ env = Environment(ENV=os.environ,
'Go': go_builder},
tools=['gcc', 'gnulink', 'g++', 'gas', 'gfortran'])
-env['CCFLAGS'] = ''
+env['CCFLAGS'] = '-Wall -Wextra -Werror'
env['CXXFLAGS'] = '-std=c++17'
env['ASFLAGS'] = '--64'
diff --git a/contents/IFS/code/c/IFS.c b/contents/IFS/code/c/IFS.c
index 2ba8cbdd2..99c4826be 100644
--- a/contents/IFS/code/c/IFS.c
+++ b/contents/IFS/code/c/IFS.c
@@ -20,7 +20,7 @@ void chaos_game(struct point *in, size_t in_n, struct point *out,
struct point cur_point = {drand(), drand()};
- for (int i = 0; i < out_n; ++i) {
+ for (size_t i = 0; i < out_n; ++i) {
out[i] = cur_point;
struct point tmp = random_element(in, in_n);
cur_point.x = 0.5 * (cur_point.x + tmp.x);
diff --git a/contents/barnsley/code/c/barnsley.c b/contents/barnsley/code/c/barnsley.c
index 17119c585..db154b777 100644
--- a/contents/barnsley/code/c/barnsley.c
+++ b/contents/barnsley/code/c/barnsley.c
@@ -44,6 +44,7 @@ struct matrix select_array(struct matrix *hutchinson_op, double *probabilities,
}
rnd -= probabilities[i];
}
+ return hutchinson_op[0];
}
// This is a general function to simulate a chaos game
diff --git a/contents/cooley_tukey/code/c/fft.c b/contents/cooley_tukey/code/c/fft.c
index 90691f373..f87e12afd 100644
--- a/contents/cooley_tukey/code/c/fft.c
+++ b/contents/cooley_tukey/code/c/fft.c
@@ -6,7 +6,7 @@
#include
#include
-void fft(double complex *x, int n) {
+void fft(double complex *x, size_t n) {
double complex y[n];
memset(y, 0, sizeof(y));
fftw_plan p;
@@ -56,8 +56,8 @@ void cooley_tukey(double complex *X, const size_t N) {
}
void bit_reverse(double complex *X, size_t N) {
- for (int i = 0; i < N; ++i) {
- int n = i;
+ for (size_t i = 0; i < N; ++i) {
+ size_t n = i;
int a = i;
int count = (int)log2((double)N) - 1;
@@ -81,7 +81,7 @@ void iterative_cooley_tukey(double complex *X, size_t N) {
bit_reverse(X, N);
for (int i = 1; i <= log2((double)N); ++i) {
- int stride = pow(2, i);
+ size_t stride = pow(2, i);
double complex w = cexp(-2.0 * I * M_PI / stride);
for (size_t j = 0; j < N; j += stride) {
double complex v = 1.0;
diff --git a/contents/euclidean_algorithm/code/c/euclidean_example.c b/contents/euclidean_algorithm/code/c/euclidean_example.c
index 16b0ce9ea..12892e1aa 100644
--- a/contents/euclidean_algorithm/code/c/euclidean_example.c
+++ b/contents/euclidean_algorithm/code/c/euclidean_example.c
@@ -1,40 +1,40 @@
#include
-#include
+#include
int euclid_mod(int a, int b) {
- a = abs(a);
- b = abs(b);
+ a = abs(a);
+ b = abs(b);
- while (b != 0) {
- int temp = b;
- b = a % b;
- a = temp;
- }
+ while (b != 0) {
+ int temp = b;
+ b = a % b;
+ a = temp;
+ }
- return a;
+ return a;
}
int euclid_sub(int a, int b) {
- a = abs(a);
- b = abs(b);
-
- while (a != b) {
- if (a > b) {
- a -= b;
- } else {
- b -= a;
- }
+ a = abs(a);
+ b = abs(b);
+
+ while (a != b) {
+ if (a > b) {
+ a -= b;
+ } else {
+ b -= a;
}
+ }
- return a;
+ return a;
}
int main() {
- int check1 = euclid_mod(64 * 67, 64 * 81);
- int check2 = euclid_sub(128 * 12, 128 * 77);
+ int check1 = euclid_mod(64 * 67, 64 * 81);
+ int check2 = euclid_sub(128 * 12, 128 * 77);
- printf("%d\n", check1);
- printf("%d\n", check2);
+ printf("%d\n", check1);
+ printf("%d\n", check2);
- return 0;
+ return 0;
}
diff --git a/contents/flood_fill/code/c/flood_fill.c b/contents/flood_fill/code/c/flood_fill.c
index d922412a1..03df6f1fb 100644
--- a/contents/flood_fill/code/c/flood_fill.c
+++ b/contents/flood_fill/code/c/flood_fill.c
@@ -25,7 +25,7 @@ int inbounds(struct point p, struct canvas c) {
return (p.x < 0 || p.y < 0 || p.y >= c.max_y || p.x >= c.max_x) ? 0 : 1;
}
-int find_neighbors(struct canvas c, struct point p, int old_val, int new_val,
+int find_neighbors(struct canvas c, struct point p, int old_val,
struct point *neighbors) {
int cnt = 0;
struct point points[4] = {
@@ -90,7 +90,7 @@ void stack_fill(struct canvas c, struct point p, int old_val, int new_val) {
c.data[cur_loc.x + c.max_x * cur_loc.y] = new_val;
struct point neighbors[4];
- int cnt = find_neighbors(c, cur_loc, old_val, new_val, neighbors);
+ int cnt = find_neighbors(c, cur_loc, old_val, neighbors);
for (int i = 0; i < cnt; ++i) {
stack_push(&stk, neighbors[i]);
@@ -160,7 +160,7 @@ void queue_fill(struct canvas c, struct point p, int old_val, int new_val) {
c.data[cur_loc.x + c.max_x * cur_loc.y] = new_val;
struct point neighbors[4];
- int cnt = find_neighbors(c, cur_loc, old_val, new_val, neighbors);
+ int cnt = find_neighbors(c, cur_loc, old_val, neighbors);
for (int i = 0; i < cnt; ++i) {
enqueue(&q, neighbors[i]);
@@ -181,7 +181,7 @@ void recursive_fill(struct canvas c, struct point p, int old_val,
c.data[p.x + c.max_x * p.y] = new_val;
struct point neighbors[4];
- int cnt = find_neighbors(c, p, old_val, new_val, neighbors);
+ int cnt = find_neighbors(c, p, old_val, neighbors);
for (int i = 0; i < cnt; ++i) {
recursive_fill(c, neighbors[i], old_val, new_val);
diff --git a/contents/gaussian_elimination/code/c/gaussian_elimination.c b/contents/gaussian_elimination/code/c/gaussian_elimination.c
index 0840b8076..6ca4ca70f 100644
--- a/contents/gaussian_elimination/code/c/gaussian_elimination.c
+++ b/contents/gaussian_elimination/code/c/gaussian_elimination.c
@@ -47,13 +47,13 @@ void gaussian_elimination(double *a, const size_t rows, const size_t cols) {
}
}
-void back_substitution(const double *a, double *x, const size_t rows,
- const size_t cols) {
+void back_substitution(const double *a, double *x, const int rows,
+ const int cols) {
for (int i = rows - 1; i >= 0; --i) {
double sum = 0.0;
- for (size_t j = cols - 2; j > i; --j) {
+ for (int j = cols - 2; j > i; --j) {
sum += x[j] * a[i * cols + j];
}
@@ -61,17 +61,17 @@ void back_substitution(const double *a, double *x, const size_t rows,
}
}
-void gauss_jordan(double *a, const size_t rows, const size_t cols) {
- int row = 0;
+void gauss_jordan(double *a, const size_t cols) {
+ size_t row = 0;
- for (int col = 0; col < cols - 1; ++col) {
+ for (size_t col = 0; col < cols - 1; ++col) {
if (a[row * cols + col] != 0) {
- for (int i = cols - 1; i > col - 1; --i) {
+ for (size_t i = cols - 1; i > col - 1; --i) {
a[row * cols + i] /= a[row * cols + col];
}
- for (int i = 0; i < row; ++i) {
- for (int j = cols - 1; j > col - 1; --j) {
+ for (size_t i = 0; i < row; ++i) {
+ for (size_t j = cols - 1; j > col - 1; --j) {
a[i * cols + j] -= a[i * cols + col] * a[row * cols + j];
}
}
@@ -99,7 +99,7 @@ int main() {
printf("\nGauss-Jordan:\n");
- gauss_jordan((double *)a, 3, 4);
+ gauss_jordan((double *)a, 4);
for (size_t i = 0; i < 3; ++i) {
printf("[");
diff --git a/contents/huffman_encoding/code/c/huffman.c b/contents/huffman_encoding/code/c/huffman.c
index 571dc8c15..4f60f5da6 100644
--- a/contents/huffman_encoding/code/c/huffman.c
+++ b/contents/huffman_encoding/code/c/huffman.c
@@ -125,7 +125,7 @@ struct tree* generate_tree(const char* str) {
}
struct heap heap = { 0 };
- for (int i = 0; i < sizeof(counts) / sizeof(int); ++i) {
+ for (size_t i = 0; i < sizeof(counts) / sizeof(int); ++i) {
if (counts[i]) {
struct tree* tree = calloc(1, sizeof(struct tree));
tree->value = (char)i;
@@ -211,8 +211,6 @@ char* encode(const char* input, struct tree** huffman_tree,
*codebook = generate_codebook(*huffman_tree);
char* result = duplicate(get_code(codebook, *input));
- int result_length = strlen(result);
- int result_capacity = result_length;
input += 1;
diff --git a/contents/split-operator_method/code/c/split_op.c b/contents/split-operator_method/code/c/split_op.c
index 0550e4ef2..ecf48e027 100644
--- a/contents/split-operator_method/code/c/split_op.c
+++ b/contents/split-operator_method/code/c/split_op.c
@@ -28,7 +28,7 @@ struct operators {
double complex *wfc;
};
-void fft(double complex *x, int n, bool inverse) {
+void fft(double complex *x, size_t n, bool inverse) {
double complex y[n];
memset(y, 0, sizeof(y));
fftw_plan p;
@@ -139,8 +139,8 @@ void split_op(struct params par, struct operators opr) {
sprintf(filename, "output%lu.dat", i);
FILE *fp = fopen(filename, "w");
- for (int i = 0; i < opr.size; ++i) {
- fprintf(fp, "%d\t%f\t%f\n", i, density[i], creal(opr.v[i]));
+ for (size_t i = 0; i < opr.size; ++i) {
+ fprintf(fp, "%ld\t%f\t%f\n", i, density[i], creal(opr.v[i]));
}
fclose(fp);
diff --git a/contents/stable_marriage_problem/code/c/stable_marriage.c b/contents/stable_marriage_problem/code/c/stable_marriage.c
index 546a0d5d1..e4f4ad2fd 100644
--- a/contents/stable_marriage_problem/code/c/stable_marriage.c
+++ b/contents/stable_marriage_problem/code/c/stable_marriage.c
@@ -20,11 +20,11 @@ void shuffle(size_t *array, size_t size) {
}
}
-void create_group(struct person *group, size_t size, bool are_men) {
+void create_group(struct person *group, size_t size) {
for (size_t i = 0; i < size; ++i) {
group[i].id = i;
group[i].partner = NULL;
- group[i].prefers = (size_t*)malloc(sizeof(size_t) * size);
+ group[i].prefers = malloc(sizeof(size_t) * size);
group[i].index = 0;
for (size_t j = 0; j < size; ++j) {
@@ -43,6 +43,7 @@ bool prefers_partner(size_t *prefers, size_t partner, size_t id, size_t size) {
return false;
}
}
+ return true;
}
void stable_marriage(struct person *men, struct person *women, size_t size) {
@@ -85,8 +86,8 @@ int main() {
struct person men[5], women[5];
- create_group(men, 5, true);
- create_group(women, 5, false);
+ create_group(men, 5);
+ create_group(women, 5);
for (size_t i = 0; i < 5; ++i) {
printf("preferences of man %zu: ", i);
From f5af3686c0ac9bbc57ca21f905c42eb56e620899 Mon Sep 17 00:00:00 2001
From: Sammy Plat
Date: Mon, 29 Nov 2021 23:38:15 +0100
Subject: [PATCH 087/146] Removed C/C++ warnings only for C++ (#957)
---
SConstruct | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/SConstruct b/SConstruct
index bd851cf0a..09c939af3 100644
--- a/SConstruct
+++ b/SConstruct
@@ -23,7 +23,7 @@ env = Environment(ENV=os.environ,
'Go': go_builder},
tools=['gcc', 'gnulink', 'g++', 'gas', 'gfortran'])
-env['CCFLAGS'] = '-Wall -Wextra -Werror'
+env['CFLAGS'] = '-Wall -Wextra -Werror'
env['CXXFLAGS'] = '-std=c++17'
env['ASFLAGS'] = '--64'
From 25d03e4711d484f84fce32521a39aa36ab8aacef Mon Sep 17 00:00:00 2001
From: Nicholas Tindle
Date: Mon, 29 Nov 2021 16:48:46 -0600
Subject: [PATCH 088/146] Move Code Reviewers from Wiki into the book (#946)
* Add code Reviewers chapter
* Add code reviews to summary
* add code reviews to how to contribute
* Update contents/code_reviews/code_reviewers.md
Co-authored-by: Dimitri Belopopsky
* Update contents/code_reviews/code_reviewers.md
Co-authored-by: Dimitri Belopopsky
* Update contents/code_reviews/code_reviewers.md
Co-authored-by: Dimitri Belopopsky
* Update contents/code_reviews/code_reviewers.md
Co-authored-by: Dimitri Belopopsky
* Apply suggestions from code review
Co-authored-by: Dimitri Belopopsky
* Update contents/code_reviews/code_reviewers.md
Co-authored-by: Sammy Plat
* Update contents/code_reviews/code_reviewers.md
Co-authored-by: Sammy Plat
* Update contents/code_reviews/code_reviewers.md
* Update contents/code_reviews/code_reviewers.md
* Update contents/code_reviews/code_reviewers.md
Co-authored-by: Dimitri Belopopsky
Co-authored-by: Sammy Plat
---
SUMMARY.md | 1 +
contents/code_reviews/code_reviewers.md | 69 +++++++++++++++++++
.../how_to_contribute/how_to_contribute.md | 4 +-
3 files changed, 73 insertions(+), 1 deletion(-)
create mode 100644 contents/code_reviews/code_reviewers.md
diff --git a/SUMMARY.md b/SUMMARY.md
index e41ba39d4..4d4597b1c 100644
--- a/SUMMARY.md
+++ b/SUMMARY.md
@@ -3,6 +3,7 @@
* [Algorithm Archive](README.md)
* [Introduction](contents/introduction/introduction.md)
* [How To Contribute](contents/how_to_contribute/how_to_contribute.md)
+ * [Code Reviewers](contents/code_reviews/code_reviewers.md)
* [Plotting](contents/plotting/plotting.md)
* [Domain Coloring](contents/domain_coloring/domain_coloring.md)
* [Iterated Function Systems](contents/IFS/IFS.md)
diff --git a/contents/code_reviews/code_reviewers.md b/contents/code_reviews/code_reviewers.md
new file mode 100644
index 000000000..0061ab996
--- /dev/null
+++ b/contents/code_reviews/code_reviewers.md
@@ -0,0 +1,69 @@
+# Code Reviewers
+
+If you are comfortable reviewing a language, please add yourself to the table below:
+
+[//]: # (To add yourself to the table, please add a link at the bottom of the article and reference yourself in the following format next to each language [@username]. If there are multiple usernames for a language, make sure to seperate them with commas)
+
+Language | Reviewers
+-|-
+asm-x64 |
+bash |
+c | [@amaras]
+c# |
+clojure |
+coconut | [@amaras]
+c++ | [@ShadowMitia]
+crystal |
+D |
+dart |
+elm |
+emojicode |
+factor |
+fortran | [@leios]
+gnuplot | [@leios]
+go |
+haskell |
+java |
+javascript | [@ntindle],[@ShadowMitia]
+julia | [@leios]
+kotlin |
+labview |
+lolcode |
+lisp |
+lua |
+matlab |
+nim |
+ocaml | [@ShadowMitia]
+php |
+piet |
+powershell |
+python | [@ntindle],[@ShadowMitia],[@amaras],[@PeanutbutterWarrior]
+r |
+racket |
+ruby |
+rust | [@ShadowMitia],[@PeanutbutterWarrior]
+scala |
+scheme |
+scratch | [@leios]
+smalltask |
+swift |
+typescript | [@ntindle]
+v |
+viml |
+whitespace |
+
+If you are comfortable reviewing a toolchain change, please add yourself to the list below:
+
+Feature | Reviewers
+-|-
+Dev Container | [@ntindle], [@ShadowMitia]
+Docker | [@ntindle], [@ShadowMitia]
+Github Actions | [@ntindle]
+Honkit |
+Scons | [@amaras],[@PeanutbutterWarrior]
+Chapters | [@leios]
+
+[@leios]: https://github.com/leios
+[@ntindle]: https://github.com/ntindle
+[@amaras]: https://github.com/amaras
+[@ShadowMitia]: https://github.com/ShadowMitia
diff --git a/contents/how_to_contribute/how_to_contribute.md b/contents/how_to_contribute/how_to_contribute.md
index 010bc9a26..abadc5385 100644
--- a/contents/how_to_contribute/how_to_contribute.md
+++ b/contents/how_to_contribute/how_to_contribute.md
@@ -15,7 +15,9 @@ For now, here are the basics for submitting code to the Algorithm Archive:
3. **CONTRIBUTORS.md**: After contributing code, please echo your name to the end of `CONTRIBUTORS.md` with `echo "- name" >> CONTRIBUTORS.md`.
4. **Building the Algorithm Archive**: Before every submission, you should build the Algorithm Archive on your own machine. To do this, install [Node](https://nodejs.org/) and use `npm install` and then `npm run serve` in the main directory (where `README.md` is). This will provide a local URL to go to to view the archive in your browser of choice. Use this server to make sure your version of the Algorithm Archive works cleanly for the chapter you are updating!
-To submit code, simply go to the `code/` directory of whatever chapter you want and add another directory for your language of choice.
+To **submit code**, go to the `code/` directory of whatever chapter you want and add another directory for your language of choice.
+
+You can also help out by **reviewing code**, if you have the ability to review a language (and want to be asked to do so), please add yourself to [the Code Reviewers list](../code_reviews/code_reviewers.md)
We use two GitBook plugins to allow users to flip between languages on different algorithms.
One is the theme-api, and the other is the include-codeblock api.
From 714f2c8827a4608637cfb614d1ff3e9f0e6fa57b Mon Sep 17 00:00:00 2001
From: Nicholas Tindle
Date: Mon, 29 Nov 2021 16:53:43 -0600
Subject: [PATCH 089/146] Speed up container start times by pulling prebuilt
the image from GitHub (#942)
* feat: pull the image from GHCR to speed up start of the container
* code review changes
* fix: spelling error and clarification
Co-authored-by: Dimitri Belopopsky
---
.devcontainer/devcontainer.json | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index e9d6bbefa..352dcca68 100644
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -1,26 +1,24 @@
-// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
-// https://github.com/microsoft/vscode-dev-containers/tree/v0.187.0/containers/ubuntu
+// For format details, see https://aka.ms/devcontainer.json.
{
- "name": "Ubuntu",
- "build": {
- "dockerfile": "../Dockerfile",
- // Update 'VARIANT' to pick an Ubuntu version: focal, bionic
- "args": { "VARIANT": "focal" }
- },
+ "name": "Arcane Algorithm Archive All Languages",
+
+ // Comment out 'image' and uncomment 'build' to test changes to the dockerfile locally
+ "image": "ghcr.io/algorithm-archivists/aaa-langs:latest",
+ // "build": {\
+ // // For config options, see the README at:https://github.com/microsoft/vscode-dev-containers/tree/v0.187.0/containers/ubuntu
+ // "dockerfile": "../Dockerfile",
+ // // Update 'VARIANT' to pick an Ubuntu version: focal, bionic
+ // "args": { "VARIANT": "focal" }
+ // },
// Set *default* container specific settings.json values on container create.
"settings": {},
-
// Add the IDs of extensions you want installed when the container is created.
"extensions": [],
- // Use 'forwardPorts' to make a list of ports inside the container available locally.
- // "forwardPorts": [],
-
- // Use 'postCreateCommand' to run commands after the container is created.
- // "postCreateCommand": "uname -a",
-
- // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
- // "remoteUser": "vscode"
+ // Use 'forwardPorts' to make a list of ports inside the container available locally (outside the container).
+ // Port : Usage
+ // 4000 : Honkit serves by default on this port
+ "forwardPorts": [4000]
}
From 9193bf73b2c44cee22ea6c46920a6a89f06b2d9d Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Mon, 29 Nov 2021 23:57:05 +0100
Subject: [PATCH 090/146] Update code_reviewers.md (#958)
---
contents/code_reviews/code_reviewers.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/contents/code_reviews/code_reviewers.md b/contents/code_reviews/code_reviewers.md
index 0061ab996..e2fd22b0a 100644
--- a/contents/code_reviews/code_reviewers.md
+++ b/contents/code_reviews/code_reviewers.md
@@ -67,3 +67,4 @@ Chapters | [@leios]
[@ntindle]: https://github.com/ntindle
[@amaras]: https://github.com/amaras
[@ShadowMitia]: https://github.com/ShadowMitia
+[@PeanutbutterWarrior]: https://github.com/PeanutbutterWarrior
From 5116769557bc415f78199f3c48673df94c25a6c0 Mon Sep 17 00:00:00 2001
From: stormofice <58337328+stormofice@users.noreply.github.com>
Date: Tue, 30 Nov 2021 05:00:31 +0100
Subject: [PATCH 091/146] Changed action to only run in main repository (#955)
Co-authored-by: Nicholas Tindle
---
.github/workflows/publish_container.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.github/workflows/publish_container.yml b/.github/workflows/publish_container.yml
index 84759dbdf..68268afa4 100644
--- a/.github/workflows/publish_container.yml
+++ b/.github/workflows/publish_container.yml
@@ -6,6 +6,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
+ if: github.repository == 'algorithm-archivists/algorithm-archive'
steps:
- uses: actions/checkout@master
- name: Publish to Registry
From 93d4a178e279169a0c79feeb2f2166a986b66237 Mon Sep 17 00:00:00 2001
From: James Schloss
Date: Tue, 30 Nov 2021 16:30:27 +0100
Subject: [PATCH 092/146] master -> main (#953)
* updating all masters to main
Co-authored-by: Dimitri Belopopsky
Co-authored-by: Dimitri Belopopsky
---
.github/workflows/deploy.yml | 2 +-
.github/workflows/publish_container.yml | 4 +-
.gitignore | 3 +
.travis.yml | 29 --
contents/IFS/IFS.md | 2 +-
.../affine_transformations.md | 2 +-
.../approximate_counting.md | 2 +-
.../backward_euler_method.md | 2 +-
.../barnes_hut_algorithm.md | 2 +-
contents/barnsley/barnsley.md | 2 +-
contents/bitlogic/bitlogic.md | 2 +-
contents/cc/license.txt | 2 +-
contents/chans_algorithm/chans_algorithm.md | 2 +-
.../choosing_a_language.md | 2 +-
.../compiled_languages/compiled_languages.md | 2 +-
.../computational_geometry.md | 2 +-
contents/computus/computus.md | 2 +-
contents/convolutions/1d/1d.md | 2 +-
contents/convolutions/2d/2d.md | 2 +-
.../convolutional_theorem.md | 2 +-
contents/cooley_tukey/cooley_tukey.md | 2 +-
contents/data_compression/data_compression.md | 2 +-
contents/data_structures/data_structures.md | 2 +-
.../decision_problems/decision_problems.md | 2 +-
.../differential_equations.md | 2 +-
contents/domain_coloring/domain_coloring.md | 2 +-
.../domain_coloring/domain_coloring.md.bak | 185 -------------
.../euclidean_algorithm.md | 2 +-
contents/flood_fill/flood_fill.md | 2 +-
contents/flood_fill/flood_fill.md.bak | 258 ------------------
contents/fortran/fortran.md | 2 +-
.../forward_euler_method.md | 2 +-
.../gaussian_elimination.md | 2 +-
contents/gift_wrapping/gift_wrapping.md | 2 +-
contents/graham_scan/graham_scan.md | 2 +-
.../how_to_contribute/how_to_contribute.md | 2 +-
contents/huffman_encoding/huffman_encoding.md | 2 +-
contents/introduction/introduction.md | 2 +-
contents/jarvis_march/jarvis_march.md | 2 +-
contents/makefiles/makefiles.md | 2 +-
.../mathematical_background.md | 2 +-
contents/matrix_methods/matrix_methods.md | 2 +-
.../monte_carlo_integration.md | 2 +-
contents/multiplication/multiplication.md | 2 +-
.../my_introduction_to_hobby_programming.md | 2 +-
contents/notation/notation.md | 2 +-
contents/physics_solvers/physics_solvers.md | 2 +-
contents/plotting/plotting.md | 2 +-
.../quantum_information.md | 2 +-
contents/quantum_systems/quantum_systems.md | 2 +-
.../split-operator_method.md | 2 +-
.../stable_marriage_problem.md | 2 +-
.../stacks_and_queues/stacks_and_queues.md | 2 +-
.../taylor_series_expansion.md | 2 +-
contents/thomas_algorithm/thomas_algorithm.md | 2 +-
contents/tree_traversal/tree_traversal.md | 2 +-
.../verlet_integration/verlet_integration.md | 2 +-
update_site.sh | 44 ---
58 files changed, 57 insertions(+), 570 deletions(-)
delete mode 100644 .travis.yml
delete mode 100644 contents/domain_coloring/domain_coloring.md.bak
delete mode 100644 contents/flood_fill/flood_fill.md.bak
delete mode 100755 update_site.sh
diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 361978a7a..e07b1fade 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -2,7 +2,7 @@ name: Build and Deploy
on:
push:
branches:
- - master
+ - main
jobs:
build-and-deploy:
diff --git a/.github/workflows/publish_container.yml b/.github/workflows/publish_container.yml
index 68268afa4..d1edec703 100644
--- a/.github/workflows/publish_container.yml
+++ b/.github/workflows/publish_container.yml
@@ -2,7 +2,7 @@ name: Publish Docker
on:
push:
branches:
- - master
+ - main
jobs:
build:
runs-on: ubuntu-latest
@@ -15,4 +15,4 @@ jobs:
name: algorithm-archivists/aaa-langs
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- registry: ghcr.io
\ No newline at end of file
+ registry: ghcr.io
diff --git a/.gitignore b/.gitignore
index 4d5a431b0..09a7ab178 100644
--- a/.gitignore
+++ b/.gitignore
@@ -528,3 +528,6 @@ build/
# Cargo artifacts
Cargo.lock
target/
+
+*.out
+*.class
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index b497e39e2..000000000
--- a/.travis.yml
+++ /dev/null
@@ -1,29 +0,0 @@
-dist: trusty
-sudo: false
-
-language: node_js
-node_js:
- - "12"
-
-before_script:
- - export BOOK_BUILD_DIR="${TRAVIS_BUILD_DIR}"/_book
- - env | sort
-
-script:
- - npm run build
- # Make sure the book built.
- - |
- book_check_file="${BOOK_BUILD_DIR}/index.html"
- if [[ ! -f "${book_check_file}" ]]; then
- echo "${book_check_file} not found"
- exit 1
- fi
-
-after_success:
- - |
- if [[ "${TRAVIS_BRANCH}" == master && "${TRAVIS_PULL_REQUEST}" == false ]]; then
- # Commits to master that are not pull requests, that is, only
- # actual addition of code to master, should deploy the book to
- # the site.
- bash "${TRAVIS_BUILD_DIR}"/tools/deploy/update_site_travis.bash
- fi
diff --git a/contents/IFS/IFS.md b/contents/IFS/IFS.md
index 9431e4631..cd503ae46 100644
--- a/contents/IFS/IFS.md
+++ b/contents/IFS/IFS.md
@@ -246,7 +246,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/affine_transformations/affine_transformations.md b/contents/affine_transformations/affine_transformations.md
index 88f140443..439440b80 100644
--- a/contents/affine_transformations/affine_transformations.md
+++ b/contents/affine_transformations/affine_transformations.md
@@ -308,7 +308,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/approximate_counting/approximate_counting.md b/contents/approximate_counting/approximate_counting.md
index ae4a765d6..5e06e43b5 100644
--- a/contents/approximate_counting/approximate_counting.md
+++ b/contents/approximate_counting/approximate_counting.md
@@ -380,7 +380,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/backward_euler_method/backward_euler_method.md b/contents/backward_euler_method/backward_euler_method.md
index ba3d72ba2..090ffb191 100644
--- a/contents/backward_euler_method/backward_euler_method.md
+++ b/contents/backward_euler_method/backward_euler_method.md
@@ -13,7 +13,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/barnes_hut_algorithm/barnes_hut_algorithm.md b/contents/barnes_hut_algorithm/barnes_hut_algorithm.md
index f4d4301b5..83c6f6003 100644
--- a/contents/barnes_hut_algorithm/barnes_hut_algorithm.md
+++ b/contents/barnes_hut_algorithm/barnes_hut_algorithm.md
@@ -16,7 +16,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/barnsley/barnsley.md b/contents/barnsley/barnsley.md
index 9c353f8b4..6b2d6b3bf 100644
--- a/contents/barnsley/barnsley.md
+++ b/contents/barnsley/barnsley.md
@@ -151,7 +151,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/bitlogic/bitlogic.md b/contents/bitlogic/bitlogic.md
index 077bf278c..c6b1dd9fd 100644
--- a/contents/bitlogic/bitlogic.md
+++ b/contents/bitlogic/bitlogic.md
@@ -148,7 +148,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/cc/license.txt b/contents/cc/license.txt
index e9c662f91..1e11bba93 100644
--- a/contents/cc/license.txt
+++ b/contents/cc/license.txt
@@ -3,7 +3,7 @@
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/chans_algorithm/chans_algorithm.md b/contents/chans_algorithm/chans_algorithm.md
index 62e125114..18daaa889 100644
--- a/contents/chans_algorithm/chans_algorithm.md
+++ b/contents/chans_algorithm/chans_algorithm.md
@@ -10,7 +10,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/choosing_a_language/choosing_a_language.md b/contents/choosing_a_language/choosing_a_language.md
index 88ad8c986..5385c309a 100644
--- a/contents/choosing_a_language/choosing_a_language.md
+++ b/contents/choosing_a_language/choosing_a_language.md
@@ -73,7 +73,7 @@ Please let me know which languages you want to cover and I'll add them here!
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/compiled_languages/compiled_languages.md b/contents/compiled_languages/compiled_languages.md
index 3f6424359..b8bac2e75 100644
--- a/contents/compiled_languages/compiled_languages.md
+++ b/contents/compiled_languages/compiled_languages.md
@@ -35,7 +35,7 @@ I just find it easier to avoid GUI's whenever possible.
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/computational_geometry/computational_geometry.md b/contents/computational_geometry/computational_geometry.md
index a99c0a4e9..bcd702fd7 100644
--- a/contents/computational_geometry/computational_geometry.md
+++ b/contents/computational_geometry/computational_geometry.md
@@ -12,7 +12,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/computus/computus.md b/contents/computus/computus.md
index 3a881cdb0..c3ec51f09 100644
--- a/contents/computus/computus.md
+++ b/contents/computus/computus.md
@@ -343,7 +343,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/convolutions/1d/1d.md b/contents/convolutions/1d/1d.md
index 9a2e652d1..ecf56a1df 100644
--- a/contents/convolutions/1d/1d.md
+++ b/contents/convolutions/1d/1d.md
@@ -304,7 +304,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Images/Graphics
- The image "[Square Wave](../res/square_wave.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
diff --git a/contents/convolutions/2d/2d.md b/contents/convolutions/2d/2d.md
index dc52157fe..e2cace847 100644
--- a/contents/convolutions/2d/2d.md
+++ b/contents/convolutions/2d/2d.md
@@ -170,7 +170,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Images/Graphics
- The image "[8bit Heart](../res/heart_8bit.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
diff --git a/contents/convolutions/convolutional_theorem/convolutional_theorem.md b/contents/convolutions/convolutional_theorem/convolutional_theorem.md
index 1034f2018..b47bec179 100644
--- a/contents/convolutions/convolutional_theorem/convolutional_theorem.md
+++ b/contents/convolutions/convolutional_theorem/convolutional_theorem.md
@@ -62,7 +62,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Images/Graphics
diff --git a/contents/cooley_tukey/cooley_tukey.md b/contents/cooley_tukey/cooley_tukey.md
index b30052e40..d528832d1 100644
--- a/contents/cooley_tukey/cooley_tukey.md
+++ b/contents/cooley_tukey/cooley_tukey.md
@@ -265,7 +265,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/data_compression/data_compression.md b/contents/data_compression/data_compression.md
index 1f48c0c99..5a04c3706 100644
--- a/contents/data_compression/data_compression.md
+++ b/contents/data_compression/data_compression.md
@@ -130,7 +130,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/data_structures/data_structures.md b/contents/data_structures/data_structures.md
index 11ae7aa4b..60680b95e 100644
--- a/contents/data_structures/data_structures.md
+++ b/contents/data_structures/data_structures.md
@@ -7,7 +7,7 @@ The fundamental building blocks of algorithms are data structures, and thus as m
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/decision_problems/decision_problems.md b/contents/decision_problems/decision_problems.md
index 064c1d067..2ab9ed612 100644
--- a/contents/decision_problems/decision_problems.md
+++ b/contents/decision_problems/decision_problems.md
@@ -14,7 +14,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/differential_equations/differential_equations.md b/contents/differential_equations/differential_equations.md
index 3cfbba1fa..0bb08349c 100644
--- a/contents/differential_equations/differential_equations.md
+++ b/contents/differential_equations/differential_equations.md
@@ -7,7 +7,7 @@ Here, we discuss many different methods to solve particular sets of differential
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/domain_coloring/domain_coloring.md b/contents/domain_coloring/domain_coloring.md
index 39159e650..9c536bb50 100644
--- a/contents/domain_coloring/domain_coloring.md
+++ b/contents/domain_coloring/domain_coloring.md
@@ -190,7 +190,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/domain_coloring/domain_coloring.md.bak b/contents/domain_coloring/domain_coloring.md.bak
deleted file mode 100644
index 8ec9129ad..000000000
--- a/contents/domain_coloring/domain_coloring.md.bak
+++ /dev/null
@@ -1,185 +0,0 @@
-# Domain coloring
-
-Domain coloring is a much more complicated plotting technique than those outlined in the [plotting chapter](../plotting/plotting.md) and is used to plot complex functions where both the input and output have imaginary and real components.
-For the code in this chapter, we will focus on languages that are easily able to plot two-dimensional images or heatmaps, instead of languages meant for number-crunching.
-That is to say that this chapter will certainly have a code implementation in gnuplot, but it will not likely have an implementation in C, Fortran, or Java because these languages do not have plotting capabilities in-built.
-
-Imagine the following function: $$f(z) = z^2$$.
-In this case, we could create a plot that looks like this:
-
-
-
-
-
-This indicates that for various input values along $$z$$, we have different function outputs from $$f(z)$$.
-Now let's imagine another function with complex input $$(z \in \mathbb{C})$$, but a purely real output $$(f(z) \in \mathbb{R})$$:
-
-$$
-f(z) = |z|
-$$
-
-In this case, each complex input has a real output.
-This can be plotted as a two-dimensional dataset like so:
-
-
-
-
-
-Here, the $$x$$-axis and $$y$$-axis represent the real and imaginary components of the input variable, respectively.
-The colorbar represents the output of $$f(z)$$.
-
-At this point, we can start to see the problem.
-If the output of $$f(z)$$ also requires plotting of the real and imaginary components, then we would need four dimensions to appropriately represent the function space, one axis for the real component and another for the imaginary component of both the input ($$z$$) and the output of $$f(z)$$!
-Unfortunately, feeble human minds are incapable of understanding four spatial dimensions without projecting onto lower dimensionality, so we need to improvise.
-
-We do this by assuming the complex output can be represented in the following form:
-
-$$
-z = re^{i \theta} = r(\cos(\theta) + i\sin(\theta))
-$$
-
-where, $$r$$ is a complex magnitude and $$\theta$$ is a complex phase.
-This is the formula for a circle in the complex plane and we can easily find $$r$$ and $$\theta$$ like so:
-
-$$
-\begin{align}
- r &= \sqrt{\text{Re}(z)^2 + \text{Im}(z)^2} \\
- \theta &= \text{atan}\left(\frac{\text{Im}(z)}{\text{Re}(z)}\right)
-\end{align}
-$$
-
-Once we have our complex function output in this form, we then color the output domain according to a color space with at least 2 independent dimensions, like RGB (Red, Green, Blue), or HSV (Hue, Saturation, Value) [CITE].
-The choice of color space is completely dependent on what the users feel is most visually intuitive.
-In any case, one dimension of the color system will be used to represent the complex magnitude of the output and another dimension of the color system will be used to represent the complex phase.
-The $$xy$$ grid will be representing the real and imaginary inputs to these functions.
-That is to say, we plug every value in the 2D complex plane into the function and then color each pixel based on the function output.
-
-As an example, let's look at the simplest function we can $$f(z) = z$$, but in this case $$z \in \mathbb{C}$$.
-If we use an RGB color scheme, where red represents $$\theta$$ and blue represents $$r$$, we can generate the following image:
-
-
-
-
-
-As a note here, there is a clear phase discontinuity along the vertical axis.
-That is to say that the complex phase wraps around the origin, ranging from 0 (clear) to $$2\pi$$ (red).
-In addition, the edges of the plot are blue because the function value increases linearly as we move from the origin.
-
-If we instead look at the function $$f(z) = z^2$$, we can generate a similar plot:
-
-
-
-
-
-Here, it is clear that the complex phase wraps around the origin twice, creating two separate phase discontinuities on top of each other.
-This indicates a $$4\pi$$ phase winding, and for some purposes, such as vortex tracking for inviscid fluids, this visualizaton is ideal, because a vortex is located precisely at the phase discontinuity [CITE].
-For other purposes, the discontinuity is visually distracting, and for this reason, many people use an HSV scheme for plotting complex functions.
-So here is the same function $$\left(f(z)=z^2\right)$$, but using hue to represent the complex phase and saturation to represent the magnitude.
-
-
-
-
-
-Here, the value for HSV was always set to 1.
-When looking at the edges of the plot, the hue changes rapidly, but each color is mirrored on the oposite edge.
-This indicates the $$4\pi$$ phase winding we saw in the RGB plots.
-Also, because the complex magnitude increases as we move further from the center of the plot, the saturation also increases.
-Thus the very center of the plot is completely washed out!
-We need to fix this in subsequent plots to make them representative of the actual data.
-
-One easy way to show that the complex magnitude is increasing as we move further from the origin is with contours.
-Essentially, at ever integer value of the magnitude, we want to draw some kind of line.
-There are a number of ways to generate these lines, and one simple way is by using an alternative shading function like so:
-
-$$
-g(r) = r-\lfloor r \rfloor.
-$$
-
-This will create the following image:
-
-
-
-
-
-This function will essentially create a smooth gradient, but because of the floor operation $$\left(\lfloor \cdot \rfloor \right)$$, the saturation will go from 0 to 1 between each integer value of the magnitude.
-Here, it is clear that the magnitude is increasing as $$z^2$$ from the origin; however, because the saturation is fluctuating so much, it is difficult to see the phase pattern next to each contour.
-This can be fixed simply by adding an offset to the shading function such that,
-
-$$
-g(r) = \frac{1}{2} + \frac{1}{2}\left(r-\lfloor r \rfloor \right).
-$$
-
-Which will produce the following image:
-
-
-
-
-
-This means that the saturation will fluctuate from $$\frac12$$ to 1 instead of from 0 to 1, which makes it way easier to see phase information next to contours.
-Again, there is a lot of ways to play with these equations, so feel free to use whatever function you want!
-As long as some sort of rounding operation is used to establish some form of integer value for the magnitude, it should be possible to create contours of various types.
-
-Unfortunately, there the changing saturation only shows changes in the complex magnitude, and changing hue only shows changes in the complex phase.
-Neither the magnitude or the phase directly show what is happening in real or imaginary space with the output.
-To show this, we might want to draw gridlines that color out grid black whenever the imaginary or real components of the output function are integer values.
-
-For example, let's go back to a simpler function $$f(z) = z$$.
-If we draw lines on this plot, corresponding to integer values in the output, we get a simple grid
-
-
-
-
-
-Like before, the choice of which function to use in order to create the gridlines is somewhat arbitrary.
-It is important to choose a function that sharply drops to 0 or peaks at 1 for all integer values, and then you multiply this by the output of $$f(z)$$.
-For these purposes, we chose the following function
-
-$$
-h(z) = |\sin(\pi\times\text{Re}(f(z)))^t|\times|\sin(\pi\times\text{Im}(f(z)))^t|,
-$$
-
-where $$t$$ is some threshold value, and was set to be 0.1 in our plot.
-A plot of h(z) for $$f(z) = z$$ where $$z\in\mathbb{R}$$ is shown below:
-
-
-
-
-
-So, putting it altogether and returning to the function of $$f(z) = z^2$$, we find the following image.
-
-
-
-
-
-Here, the diagonal lines through the center represent integer values along the imaginary axis for $$f(z)$$ and the vertical and horizontal represent integer values of the real axis for $$f(z)$$.
-
-## Example Code
-
-Here is the full script to generate a domain colored output of $$f(z)=z^2$$.
-
-### Bibliography
-
-{% references %} {% endreferences %}
-
-
-
-## License
-
-##### Code Examples
-
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
-
-##### Text
-
-The text of this chapter was written by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-
-[
](https://creativecommons.org/licenses/by-sa/4.0/)
-
-##### Images/Graphics
-
-##### Pull Requests
-
-The following pull requests have modified the text or graphics of this chapter:
-- none
diff --git a/contents/euclidean_algorithm/euclidean_algorithm.md b/contents/euclidean_algorithm/euclidean_algorithm.md
index 1d6211a37..cebf550ba 100644
--- a/contents/euclidean_algorithm/euclidean_algorithm.md
+++ b/contents/euclidean_algorithm/euclidean_algorithm.md
@@ -302,7 +302,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/flood_fill/flood_fill.md b/contents/flood_fill/flood_fill.md
index 4c7e5936e..62348f107 100644
--- a/contents/flood_fill/flood_fill.md
+++ b/contents/flood_fill/flood_fill.md
@@ -279,7 +279,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/flood_fill/flood_fill.md.bak b/contents/flood_fill/flood_fill.md.bak
deleted file mode 100644
index d15b1ef97..000000000
--- a/contents/flood_fill/flood_fill.md.bak
+++ /dev/null
@@ -1,258 +0,0 @@
-# Flood Fill
-
-Flood fill is a method that is surprisingly useful in a large number of different situations and keeps finding me wherever I go.
-When I was completing my PhD, I had an idea to track superfluid vortices by using flood fill as a way to help mask out unnecessary features of the simulation.
-When I was making a terminal game, I thought of creating an animation that was just flood fill in disguise.
-When I decided to play minesweeper or Go with my girlfriend, flood fill was used in both!
-
-Flood fill is probably most commonly known as the "Bucket Fill" application in most art programs {{ "gimp_bucket" | cite }}.
-It's usually indicated by an icon that looks like a bucket and is known to fill in any enclosed area, as shown below:
-
-
-
-
-
-Because flood fill is incredibly common, there are a large number of variations to the method, some of which are more optimal than others.
-For this chapter, we will cover the basics: how to fill a domain in a quick and dirty way.
-In subsequent chapters, we will continue our journey by creating more and more efficient flood fill methods, including scanline-based and fixed memory methods {{ "torbert2016" | cite }}.
-
-I have decided to split the chapter up for a few important reasons:
-1. I did not want to flood the Algorithm Archive with flood fill methods all at the same time.
-I feel it's worth letting each chapter sit for a bit while we savour it's unique flavour.
-2. Many users are implementing versions of each algorithm in their own languages and it is difficult to review and submit code for chapters with a lot of code chunks.
-Several sub-chapters with less code is easier for everyone.
-3. I am kinda under a time-constraint right now and wanted to make sure we regularly get content into the Algorithm Archive.
-
-So, without further a-do, let's hop right into it!
-
-
-## What does flood fill do?
-
-Flood fill is essentially composed of 2 parts:
-1. Determining the extents of the domain to fill
-2. Walking through all elements within a domain and changing some property
-
-For the purposes of this chapter, we will be using a set of floating-point values that range from 0 to 1 instead of a color-space like RGB.
-Though bucket fill is always used in art programs in some sort of color space, flood fill is more general and can be used in a space with any type of element.
-As such, it makes sense to use a simpler element type so we can better understand the method.
-
-So how do we go about finding the extents of the domain to fill?
-
-Here, a domain will be defined as any connected set of elements in an $$n$$-dimensional space whose values do not vary beyond a pre-defined threshold.
-As an example, if we take a circle embedded into a 2-dimensional grid, we have 3 separate domains:
-1. Inside the circle where all elements are 0.
-2. The circle, itself, where the elements are set to 0.75.
-3. Outside the circle where all elements are similarly 0.
-
-
-
-
-
-Though there are some more complicated ways to determine the extents of the domain, we will not focus on this aspect of the flood fill method for the remainder of this chapter and instead leave it for subsequent chapters.
-So now we will focus on the process of walking through each element in the domain and changing some property.
-
-## Domain traversal
-
-As before, the simplest example to work with is that of an image, where each element in our domain is a single pixel.
-Here, we can connect each pixel to all other pixels in its vicinity, like so:
-
-
-
-
-
-In this image, a border is shown between each individual pixel and a grid is superimposed to show how each pixel is connected to its neighbors.
-This means that each element has 4 neighbors: north, south, east, and west.
-We could also include northeast, southeast, southwest, and northwest if we wanted to do an 8-way fill, but we will restrict the discussion to the 4-way fill for now, as the method is essentially the same and slightly easier to understand with fewer elements to worry about.
-
-By connecting each pixel to its neighbors in this way, the flood fill operation becomes a process of graph traversal, not too dissimilar from the [tree traversal](../tree_traversal/tree_traversal.md) methods described before.
-This means that after selecting our initial location, we can then traverse through all elements in either a depth-first or breadth-first fashion.
-We will be covering the following this chapter:
-
-1. Finding all neighbours
-2. Depth-first node traversal
-3. Breadth-first node traversal and small-scale optimizations
-
-So let's start by discussing how we might go about finding the neighbors to fill.
-
-### Finding all neighbors
-
-The first step of this method is to query the location of all possible neighbors.
-At first glance, this seems rather straightforward.
-One simply needs to look up, down, left, and right of the current location and add those elements to the list of neighbors if they are:
-
-1. On the canvas
-2. Have a value *close enough* to the old value we would like to replace
-
-In code, this might look like this:
-
-{% method %}
-{% sample lang="jl" %}
-[import:37-55, lang:"julia"](code/julia/flood_fill.jl)
-{% endmethod %}
-
-
-This code is set up to return a vector of elements to then use for subsequent sections.
-
-### Depth-first node traversal
-
-Now that we have the ability to find all neighboring elements, we can proceed to traverse through those nodes in the most straightforward way: recursion.
-
-In code, it might look like this:
-
-{% method %}
-{% sample lang="jl" %}
-[import:106-118, lang:"julia"](code/julia/flood_fill.jl)
-
-All Julia code snippets for this chapter rely on an exterior `color!(...)` function, defined as
-
-[import:23-35, lang:"julia"](code/julia/flood_fill.jl)
-{% endmethod %}
-
-The above code continues recursing through available neighbors as long as neighbors exist, and this should work so long as we are adding the correct set of neighbors.
-
-Additionally, it is possible to do the same type of traversal by managing a stack, like so:
-
-{% method %}
-{% sample lang="jl" %}
-[import:57-77, lang:"julia"](code/julia/flood_fill.jl)
-{% endmethod %}
-
-This is ultimately the same method of traversal as before; however, because we are managing our own data structure, there are a few distinct differences:
-1. The manually managed stack could be slightly slower and potentially more memory-intensive
-2. It is easy to reach the maximum recursion depth on certain hardware with the recursive method, so it is best to use the stack-based implementation in those cases.
-
-If we were to use either of these methods to fill a circle embedded in a two dimensional domain, we would see the following
-
-
-
-
-
-Here, we see that these methods will traverse through one direction first before filling from there.
-This is potentially the easiest method to write, but it is not the most intuitive fill pattern.
-I suspect that if someone was asked to fill the contents of the circle on their own, they would fill it more evenly from the center, like so:
-
-
-
-
-
-This is simply another traversal strategy known as breadth-first traversal and comes with its own set of caveats.
-We will discuss this further in the next subsection
-
-### Breadth-first node traversal and small-scale optimizations
-
-Breadth-first node traversal is as simple as switching the stack in the depth-first strategy with a queue.
-The code would look something like this:
-
-{% method %}
-{% sample lang="jl" %}
-[import:80-104, lang:"julia"](code/julia/flood_fill.jl)
-{% endmethod %}
-
-Now, there is a small trick in this code that must be considered to make sure it runs optimally.
-Namely, the nodes must be colored *when they are being enqueued*, not when visiting the node.
-At least for me, it was not immediately obvious why this would be the case, but let me try to explain.
-
-Let's imagine that we decided to write code that colored all neighboring nodes only when visiting them.
-When querying all possible neighbors, we will add 4 elements to the queue for the north, south, east, and west neighbors of the initial node, as shown below:
-
-
-
-
-
-Now let's imagine we travel east first.
-It then enqueues three more nodes: north, south, and east again.
-This is shown below:
-
-
-
-
-
-It does not enqueue its west neighbour because this has already been colored.
-At this stage, we will have six nodes ready to be colored and 2 that are already colored.
-Now let's say we travel north next.
-This node will enqueue three more nodes: west, north, and east, as shown below:
-
-
-
-
-
-The problem is that the east element has *already been enqueued for coloring by the previous node*!.
-This shared element is colored in red.
-As we progress through all four initial neighbours, we will find 4 nodes that are doubly enqueued: all directions diagonal to the initial location!
-This is again shown below:
-
-
-
-
-
-As the number of nodes increases, so does the number of duplicate nodes.
-A quick fix is to color the nodes *when they are being enqueud* like in the example code above.
-When doing this, duplicates will not be enqueued with a breadth-first scheme because they will already be colored when other nodes are trying to find their neighbors.
-This created a node connection pattern like so:
-
-
-
-
-
-As some final food for thought: why wasn't this a problem with the depth-first strategy?
-The simple answer is that it actually was an issue, but it was way less prevalent.
-With the depth-first strategy, a number of unnecessary nodes are still pushed to the stack, but because we consistently push one direction before spreading out to other directions, it is more likely that the nodes have filled neighbours when they are looking for what to fill around them.
-
-Simply put: depth-first traversal is slightly more efficient in this case unless you can color as querying for neighbors, in which case breadth-first is more efficient.
-
-## Conclusions
-
-As stated before, the method discussed in this chapter is just the tip of the iceberg and many other flood fill methods exist that are likely to be more efficient for most purposes.
-These will all be covered in subsequent chapters which will come out somewhat regularly throughout the next few months, lest we flood that archive with flood fill methods.
-
-## Example Code
-
-The example code for this chapter will be the simplest application of flood fill that still adequately tests the code to ensure it is stopping at boundaries appropriately.
-For this, we will create a two dimensional array of floats, all starting at 0.0, and then set a single vertical line of elements at the center to be 1.0.
-After, we will fill in the left-hand side of the array to be all ones by choosing any point within the left domain to fill.
-
-{% method %}
-{% sample lang="jl" %}
-[import, lang:"julia"](code/julia/flood_fill.jl)
-{% endmethod %}
-
-
-### Bibliography
-
-{% references %} {% endreferences %}
-
-
-
-## License
-
-##### Code Examples
-
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
-
-##### Text
-
-The text of this chapter was written by [James Schloss](https://github.com/leio) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-
-[
](https://creativecommons.org/licenses/by-sa/4.0/)
-
-##### Images/Graphics
-- The image "[Example Bucket Fill](res/example.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-- The image "[Circle Domains](res/simple_circle.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-- The image "[Grid 1](res/grid_1.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-- The image "[Grid 2](res/grid_2.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-- The image "[Grid 3](res/grid_3.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-- The image "[Grid 4](res/grid_4.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-- The image "[Grid 5](res/grid_5.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-- The image "[Grid 6](res/grid_6.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-- The video "[Stack Fill](res/recurse_animation.mp4)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-- The video "[Queue Fill](res/queue_animation.mp4)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
-
-
diff --git a/contents/fortran/fortran.md b/contents/fortran/fortran.md
index f705d3c17..491a33b6e 100644
--- a/contents/fortran/fortran.md
+++ b/contents/fortran/fortran.md
@@ -6,7 +6,7 @@ Alright, so here's the thing about Fortran. It's old.
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/forward_euler_method/forward_euler_method.md b/contents/forward_euler_method/forward_euler_method.md
index f97ff27a2..dfb185431 100644
--- a/contents/forward_euler_method/forward_euler_method.md
+++ b/contents/forward_euler_method/forward_euler_method.md
@@ -156,7 +156,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/gaussian_elimination/gaussian_elimination.md b/contents/gaussian_elimination/gaussian_elimination.md
index 8caf869ed..4eaf61570 100644
--- a/contents/gaussian_elimination/gaussian_elimination.md
+++ b/contents/gaussian_elimination/gaussian_elimination.md
@@ -591,7 +591,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/gift_wrapping/gift_wrapping.md b/contents/gift_wrapping/gift_wrapping.md
index 176463672..59bbc4d91 100644
--- a/contents/gift_wrapping/gift_wrapping.md
+++ b/contents/gift_wrapping/gift_wrapping.md
@@ -14,7 +14,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/graham_scan/graham_scan.md b/contents/graham_scan/graham_scan.md
index 7b84f3acd..7b46422cb 100644
--- a/contents/graham_scan/graham_scan.md
+++ b/contents/graham_scan/graham_scan.md
@@ -105,7 +105,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/how_to_contribute/how_to_contribute.md b/contents/how_to_contribute/how_to_contribute.md
index abadc5385..b8aa1d624 100644
--- a/contents/how_to_contribute/how_to_contribute.md
+++ b/contents/how_to_contribute/how_to_contribute.md
@@ -38,7 +38,7 @@ Thanks for all the support and considering contributing to the Algorithm Archive
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/huffman_encoding/huffman_encoding.md b/contents/huffman_encoding/huffman_encoding.md
index 3772c97ca..881c4c47c 100644
--- a/contents/huffman_encoding/huffman_encoding.md
+++ b/contents/huffman_encoding/huffman_encoding.md
@@ -110,7 +110,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/introduction/introduction.md b/contents/introduction/introduction.md
index dccd6e82a..b9efc5c75 100644
--- a/contents/introduction/introduction.md
+++ b/contents/introduction/introduction.md
@@ -22,7 +22,7 @@ So I guess that's all for now. Because this book is freely available online, I m
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/jarvis_march/jarvis_march.md b/contents/jarvis_march/jarvis_march.md
index 20929d4ad..7fee2e681 100644
--- a/contents/jarvis_march/jarvis_march.md
+++ b/contents/jarvis_march/jarvis_march.md
@@ -62,7 +62,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/makefiles/makefiles.md b/contents/makefiles/makefiles.md
index 3e23c926d..642065257 100644
--- a/contents/makefiles/makefiles.md
+++ b/contents/makefiles/makefiles.md
@@ -6,7 +6,7 @@ COMING SOON!
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/mathematical_background/mathematical_background.md b/contents/mathematical_background/mathematical_background.md
index 4ed9afb45..fa0f36839 100644
--- a/contents/mathematical_background/mathematical_background.md
+++ b/contents/mathematical_background/mathematical_background.md
@@ -16,7 +16,7 @@ In those cases, we will place the mathematical methods in more relevant sections
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/matrix_methods/matrix_methods.md b/contents/matrix_methods/matrix_methods.md
index 96ae1c8b7..89f3f8e3b 100644
--- a/contents/matrix_methods/matrix_methods.md
+++ b/contents/matrix_methods/matrix_methods.md
@@ -17,7 +17,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/monte_carlo_integration/monte_carlo_integration.md b/contents/monte_carlo_integration/monte_carlo_integration.md
index 964de7bbe..c01a6cbbd 100644
--- a/contents/monte_carlo_integration/monte_carlo_integration.md
+++ b/contents/monte_carlo_integration/monte_carlo_integration.md
@@ -220,7 +220,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/multiplication/multiplication.md b/contents/multiplication/multiplication.md
index ea430dee2..75ce2e9cb 100644
--- a/contents/multiplication/multiplication.md
+++ b/contents/multiplication/multiplication.md
@@ -25,7 +25,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/my_introduction_to_hobby_programming/my_introduction_to_hobby_programming.md b/contents/my_introduction_to_hobby_programming/my_introduction_to_hobby_programming.md
index 98ad6607d..eb3260ce9 100644
--- a/contents/my_introduction_to_hobby_programming/my_introduction_to_hobby_programming.md
+++ b/contents/my_introduction_to_hobby_programming/my_introduction_to_hobby_programming.md
@@ -72,7 +72,7 @@ Basically, since the first time I was able to directly interact with my computer
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/notation/notation.md b/contents/notation/notation.md
index 793698d0b..f8242ddde 100644
--- a/contents/notation/notation.md
+++ b/contents/notation/notation.md
@@ -208,7 +208,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/physics_solvers/physics_solvers.md b/contents/physics_solvers/physics_solvers.md
index 6192b4681..12d24c366 100644
--- a/contents/physics_solvers/physics_solvers.md
+++ b/contents/physics_solvers/physics_solvers.md
@@ -12,7 +12,7 @@ For example, there are many different ways to solve the Schrödinger equation, h
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/plotting/plotting.md b/contents/plotting/plotting.md
index 2ad1ae63f..0fd858f6b 100644
--- a/contents/plotting/plotting.md
+++ b/contents/plotting/plotting.md
@@ -574,7 +574,7 @@ Here, we have provided all of the essential skills to plot any data that comes f
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/quantum_information/quantum_information.md b/contents/quantum_information/quantum_information.md
index 56636b724..7916d36b7 100644
--- a/contents/quantum_information/quantum_information.md
+++ b/contents/quantum_information/quantum_information.md
@@ -33,7 +33,7 @@ As always, this section will be updated as we add more algorithms to the list.
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/quantum_systems/quantum_systems.md b/contents/quantum_systems/quantum_systems.md
index c602aaea1..71eb9305a 100644
--- a/contents/quantum_systems/quantum_systems.md
+++ b/contents/quantum_systems/quantum_systems.md
@@ -260,7 +260,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/split-operator_method/split-operator_method.md b/contents/split-operator_method/split-operator_method.md
index ad4fd6c0e..1af23e331 100644
--- a/contents/split-operator_method/split-operator_method.md
+++ b/contents/split-operator_method/split-operator_method.md
@@ -203,7 +203,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/stable_marriage_problem/stable_marriage_problem.md b/contents/stable_marriage_problem/stable_marriage_problem.md
index 2e8850a01..dc7f031ab 100644
--- a/contents/stable_marriage_problem/stable_marriage_problem.md
+++ b/contents/stable_marriage_problem/stable_marriage_problem.md
@@ -68,7 +68,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/stacks_and_queues/stacks_and_queues.md b/contents/stacks_and_queues/stacks_and_queues.md
index 89a77be9a..5d637deb3 100644
--- a/contents/stacks_and_queues/stacks_and_queues.md
+++ b/contents/stacks_and_queues/stacks_and_queues.md
@@ -35,7 +35,7 @@ Here is a simple implementation of a queue:
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/taylor_series_expansion/taylor_series_expansion.md b/contents/taylor_series_expansion/taylor_series_expansion.md
index 29ba87be4..76effd506 100644
--- a/contents/taylor_series_expansion/taylor_series_expansion.md
+++ b/contents/taylor_series_expansion/taylor_series_expansion.md
@@ -51,7 +51,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/thomas_algorithm/thomas_algorithm.md b/contents/thomas_algorithm/thomas_algorithm.md
index 81bb47617..607e9741a 100644
--- a/contents/thomas_algorithm/thomas_algorithm.md
+++ b/contents/thomas_algorithm/thomas_algorithm.md
@@ -147,7 +147,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/tree_traversal/tree_traversal.md b/contents/tree_traversal/tree_traversal.md
index 5dc6657e0..566aca469 100644
--- a/contents/tree_traversal/tree_traversal.md
+++ b/contents/tree_traversal/tree_traversal.md
@@ -388,7 +388,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/contents/verlet_integration/verlet_integration.md b/contents/verlet_integration/verlet_integration.md
index 80d719bef..5d993b4f4 100644
--- a/contents/verlet_integration/verlet_integration.md
+++ b/contents/verlet_integration/verlet_integration.md
@@ -234,7 +234,7 @@ MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
##### Code Examples
-The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/master/LICENSE.md)).
+The code examples are licensed under the MIT license (found in [LICENSE.md](https://github.com/algorithm-archivists/algorithm-archive/blob/main/LICENSE.md)).
##### Text
diff --git a/update_site.sh b/update_site.sh
deleted file mode 100755
index 0ccf8f7bb..000000000
--- a/update_site.sh
+++ /dev/null
@@ -1,44 +0,0 @@
-#!/usr/bin/env bash
-
-if [ $# -ge 1 ]; then
- if [ $# -eq 2 ]; then
- out_dir="$2"
- else
- if [ -z ${AAA_DIR+x} ]; then
- echo "No output directory specified"
- exit 1
- fi
- out_dir="$AAA_DIR"
- fi
-
- if [[ ! -d "$out_dir" ]]; then
- echo "$out_dir is not a directory"
- exit 1
- fi
-
- npm run build . /tmp/algorithm-archivists.github.io
-
- if [ $? -ne 0 ]; then
- echo "Failed to build the book"
- exit 1
- fi
-
- cd "$out_dir"
- git reset --hard && \
- git clean -dfx && \
- git pull origin master
-
- if [ $? -ne 0 ]; then
- echo "Failed to prepare repository"
- exit 1
- fi
-
- cp -r /tmp/algorithm-archivists.github.io/* .
- rm -r /tmp/algorithm-archivists.github.io
- git add .
- git commit -m "$1"
- git push origin master
-
-else
- echo "No commit message specified"
-fi
From 1eaaa06690c99c9385411b7ec74010470b7d4c9f Mon Sep 17 00:00:00 2001
From: James Schloss
Date: Tue, 30 Nov 2021 16:35:19 +0100
Subject: [PATCH 093/146] adding histogram subsection for plotting chapter
(#960)
---
contents/plotting/code/gnuplot/histogram.gp | 22 +++++
contents/plotting/data/rand.dat | 100 ++++++++++++++++++++
contents/plotting/plotting.md | 40 +++++++-
contents/plotting/res/gnuplot/histogram.png | Bin 0 -> 8844 bytes
4 files changed, 158 insertions(+), 4 deletions(-)
create mode 100644 contents/plotting/code/gnuplot/histogram.gp
create mode 100644 contents/plotting/data/rand.dat
create mode 100644 contents/plotting/res/gnuplot/histogram.png
diff --git a/contents/plotting/code/gnuplot/histogram.gp b/contents/plotting/code/gnuplot/histogram.gp
new file mode 100644
index 000000000..9ef432236
--- /dev/null
+++ b/contents/plotting/code/gnuplot/histogram.gp
@@ -0,0 +1,22 @@
+# This is the size of each bin
+bin_width = 1;
+
+# This takes the data and determins which bin id it should fall into
+bin_id(x) = floor(x/bin_width)
+
+# This modifies each bin to be the correct width and also centers it over the
+# correct number
+bin(x) = bin_width * ( bin_id(x) + 0.5 )
+
+# Starts the y-axis at 0
+set yrange [0:]
+
+# Removes legend
+unset key
+
+# Sets a fill style for "fillsteps"
+set style fill solid 1.00 border
+
+# The column number to be histogrammed is 1, change $1 to another number if
+# you want to plot another column
+plot '../../data/rand.dat' u (bin($1)):(1) t 'data' smooth frequency w fillsteps
diff --git a/contents/plotting/data/rand.dat b/contents/plotting/data/rand.dat
new file mode 100644
index 000000000..22608d0a6
--- /dev/null
+++ b/contents/plotting/data/rand.dat
@@ -0,0 +1,100 @@
+9
+6
+8
+8
+3
+7
+1
+4
+2
+9
+6
+1
+5
+1
+7
+3
+7
+4
+6
+5
+6
+1
+4
+6
+4
+8
+9
+3
+9
+9
+8
+3
+6
+9
+2
+1
+2
+1
+3
+6
+3
+1
+4
+1
+2
+9
+1
+4
+8
+2
+5
+5
+5
+1
+3
+2
+6
+3
+1
+6
+8
+5
+2
+1
+7
+8
+6
+1
+9
+2
+2
+4
+9
+5
+3
+1
+8
+7
+7
+8
+7
+3
+8
+1
+7
+5
+5
+5
+8
+6
+8
+9
+9
+1
+3
+8
+2
+6
+7
+3
diff --git a/contents/plotting/plotting.md b/contents/plotting/plotting.md
index 0fd858f6b..c4bde1ecf 100644
--- a/contents/plotting/plotting.md
+++ b/contents/plotting/plotting.md
@@ -1,7 +1,7 @@
# Plotting
Plotting is an essential tool for visualizing and understanding important details of several algorithms and methods and is necessary for studies in various areas of computational science.
-For many languages, such as python, julia, and matlab, it is relatively straightforward to create simple plots for various types of data; however, for several other languages, like fortran, C/C++, and java, plotting can be a chore.
+For many languages, such as python, julia, and matlab, it is relatively straightforward to create simple plots for various types of data; however, for several other languages, like Fortran, C/C++, and java, plotting can be a chore.
Because the Algorithm Archive strives to be language agnostic, we do not want to favor any particular set of languages and have decided instead to output all data that needs plotting into a file format that can easily be read in by various plotting scripts separate from the algorithm implementations.
If you are implementing any algorithm in a language found on this page, you should be able to modify your existing code to allow for on-the-fly plotting.
@@ -485,7 +485,7 @@ In the case of two-dimensional image output, the data file be similar, but this
[import](data/2d_sample_low_res.dat)
-It is expected that the number of columns does not vary in each row and that we are working with an $$n \times m$$ matrix which can be simply plotted as a series of pixels that scale in color according to some defined colorbar.
+It is expected that the number of columns does not vary in each row and that we are working with an $$n \times m$$ matrix which can be simply plotted as a series of pixels that scale in color according to some defined color bar.
{% method %}
{% sample lang="gnuplot" %}
@@ -503,7 +503,7 @@ splot "sample_data.dat" matrix with image
{% endmethod %}
-#### changing the colorbar
+#### changing the color bar
For plotting images from data files, we will often need to specify how we color the image by setting a custom color bar
@@ -537,7 +537,7 @@ For the purposes of the Algorithm Archive, this space is mainly two-dimensional;
We will update this section if three-dimensional scatter plots are required.
For the purposes of the Algorithm Archive, scatter plot data will be output as a series of $$x$$ and $$y$$ pairs, where each row has an $$x$$ and a $$y$$ value, separated by a tab character.
-For example, a datafile might look like this:
+For example, a data file might look like this:
[import:1-10](data/scatterplot_data.dat)
@@ -561,6 +561,37 @@ Here, we have chosen `pointtype 7`, simply because it is easier to see when comp
{% endmethod %}
+# Histograms
+
+Many different algorithms will output data as a series of points that must be organized into separate bins before anyone can make sense of the data.
+For example, here are 10 values from a set of 100 randomly generated integers between 1 and 9:
+
+[import:50-60](data/rand.dat)
+
+Someone might ask, "How many 1s show up in this string of numbers?"
+Similarly, someone might want to know how many 1s we have *in comparison* to the number of 2s (or 3s or 4s, etc).
+To do this, we would create a set of bins and then iterate through the data, adding one to a bin every time we find a corresponding number.
+Note that the bins do not necessarily need to be sequential integer values and that for floating point numbers, the input might need to be rounded.
+You can even histograms objects or anything that else that can be categorized.
+
+For the data that we have shown above, we might create a histogram that looks like this:
+
+
+
+
+
+And here is a plotting script to generate it:
+
+{% method %}
+[import](code/gnuplot/histogram.gp)
+{% sample lang="gnuplot" %}
+
+For this, we are using a fill style to use with `fillsteps` so the histogram is colored, but if you just want a line, you could remove the fill style and use `histeps` instead.
+As another note, we are using `t 'data' smooth frequency`, which essentially turns the input numbers into a small, binned array to plot.
+{% endmethod %}
+
+Note that this code rounds the input in the case of floating point numbers.
+
If you are interested in seeing this type of plot generate fractal patterns, please look at the chapter on [iterated function systems](../IFS/IFS.md).
## Conclusions
@@ -607,6 +638,7 @@ The text of this chapter was written by [James Schloss](https://github.com/leios
- The image "[gnuplot_2d_sample](res/gnuplot/2d_sample.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
- The image "[gnuplot_2d_sample_colorbar](res/gnuplot/2d_sample_cb.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
- The image "[gnuplot_scatterplot](res/gnuplot/scatterplot.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
+- The image "[gnuplot_histogram](res/gnuplot/histogram.png)" was created by [James Schloss](https://github.com/leios) and is licensed under the [Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0/legalcode).
{% endmethod %}
diff --git a/contents/plotting/res/gnuplot/histogram.png b/contents/plotting/res/gnuplot/histogram.png
new file mode 100644
index 0000000000000000000000000000000000000000..5249f45eb958ef07bc0e3a945d4af81b070b71d8
GIT binary patch
literal 8844
zcmdUVXH=7ExAp^wI#lOn6a^uuGcX9q0MevcLHZa(ngPT@FVZ^*Dk>r>O*#SrX+h~7
zEJz0-gx-6TMYCDhr)KOz+;bB1#gkAme
zMKppi1|kT<*nUR%pNc}wLin@SLR0M`vP=J$Qk@xrAOeW`#dB9Z6PAX33?toWyK5bF
zPUv46uU@|N>qXZ33+el(`#CHgJWPCBRB`6TZ!uA^Zh2|(nRbLWthPeAQASS%F62^|
zmY5#HLCor&dyMnW=wGHze{5X|-}Wo-yTxob?cXuGzSdysj{IznAbSq{j}No^Si-yx5tD_R+<)5dkn6Q;(P$fdhW3SrZ2eVU>rW1f?BzJRMPA6aEoVTG
z5c7AuC{(g~grKxyfeqm#HWKbzRrO)Lg+zSYPe1*nk%jW#8Xp+d$nPa;@F9o@MIViS
z>*eJojGdU6AQR`(BD>~XU1r*;vuWWn4nuMlpB~xzzHYiz(6{t%{#Q&!Vof1t+ub8v
z<%mtDBM#rc*2LgGmEMx*TH-t~rE|tae#u!VF^_(d4a#)fNDv1bTkfuzh?&`FiT&Uq
zZf;w7*x0*qd*u`rtF+@~;L0Sm=H}*8n2KKx97vgBLy%9_Jm#F7;g-pM8nAQjtM4Z$31IW=FSrexWT2sc_3F-g^6nxbCkAb^G*Eow#tn_Ea+ewY
zGp<&vWA8nN?y9NNUrj;GtjABBuvdmVP`g7xLLNM*udk<0rz9sQlfruPOm?>>!-a)~
zLpV_mglvM}=5TMC8fUyCg4Dg2Z;-+-lG)BAG5bkp`ZuRao$~1FZ?=w6n6sNIqCb7X
zy0bsuF&+uq9?`jZnMY%nm=x^?iue@V
z@87@wb!y6OX@C^qXKZ0Hp{qi@s;8%i!Pu{}BZ!>b;AoI(h3nk*`iyRpVt<9(!Y)Z3
zcEhB^PW|%bx7+9Qk%lV6A|eReXns~=c96xUnp?lGB=iz_}KX4|XK
zx(6A$&bIeLTGYD*b?ItG8uWp)i%UdAME<0$*rCw2O$14agzJQvcJ>#)kK60HKHcW#
z=Jqj!v$VzpjZTf^k-DRG@#3c#Gyklqe<8>%Yo4*kTtcd8$|-SsFB}aJ6oWlkO>%l9aUbKaL;?F-!S@$v(^FSJG6e)8^s)N;q0;
z1HX^x@#8_h~ey>ig5Bgkkw+nG$*w%$eSJ|^cQ#Q+*6Z8Xhp3a{;$}rwol2WScpOGSMWuFjc9xx2=Ew4MY%rKsd%HO}
zEK@f}SLWun<2i5Ny44yhB_t>3IRa=r-KM7z#w&YDSh#7L7eSny&V<%m46azo#AB{s
zk3`qh)VzE5PQ(D0yZfiQ`eW1l&Gq%d8r#!66w-pnTo-m{XGiebyj^Xf>C01iozZ@r
zZ)IgeGFy}>!`SEX^nk;A!|b^VvvLw^$}tN!DI(^!e!K)I0y6m|c4%lQH8r(8Ny+v{
zH#G^}FcOWf_SxK+CulkW;vN5$sp?kK%huLbm7Q_Uw(VP(n{0c76JC>L%rD?{n2FCe=_ye^dc*lcH7EsbnT@74|uBry0b^=6%skx|1l
zK0S>iVW07tx&fQR9vWHD*yQbPfEH0f!3-diaHS2ykG*x?v#jhKKEI_5dH=rXT_9
zZL+{<#WmG%OjPhViS6p@I)40kK|#UE@2`o;NnU?CLFAQ=*sT8sz#$4?~1W1;ou{TL8gUVmO_YsUS6;Qzh{qC2^!yu6&5nHiREvA=MJfD$`(s=cj^
zegFR1f#RG*P%R*e0+@F`^EwvU_AYM>I-+Fk`hY_H*E=gJD!9#jB?JV_zoY;vo#Rwo
zt%LowuK@+J&ys>vmX#?|iFmUBYH?}lCILmAMD1?PWhVQ7YZ5wm@Ze~`E_I~Z2OvuR
z2fOyu4iPCUwT^x#jvX79MP=vZVF1*8eRrTdaw2(@you0b^io`0Tm<1X==&3baA@L%
zZeX!kOqHhuY(K3rm{a*p^$f<{z2y5Fmid=Sp4RJMk~$}56%Y`By?W)!73z!inT~iZ!G*gB;=mubw=7_n
zrjbP?63Hik3P=qMNST)v&sbeu-J3UWbd|T$3kuM}x8E7kc4kyOX20C%esjgR9eOHZ
z3B^Q*AJ8ySXnlQs%H~S47o(3Ehsp6rXv}}$M-j7
z@7pS$Nvhn)(cGBrJV6J&8D^yJ@#?~U2IRomz<=tH62lMbDe}XTLCx|DF<9w9geg!A
z)0`8Pgv`{5S^cj(!+*nN%oeLmfjj{%z{<+1;5z$aQR`YLdn4n0a`N)qYYnJU
zL($<%kB*KG@$Xb}#lj->GgRbrENpyey(F;A*w`2#J<~pp1bG)h8JP`IubGO=^wYoV
zb{E9#FWlS>_4S|w0NIC!g|y>t$;5~ADP;U5kjFUq&bR`KN=p~h8euz?6cs;w_)wGp
z>Of8##pLehhN<=@>FFv-d#;W>dh`f7ku>%`IOkd(%l`deoT0fVif9t)P+0y{a-!Vb
z33yZO+0nK2bz4HVzDv!Yy@!L}o6l4ufxOA@&8>8e#);Q@F
zJDC8=Qt6Mvg_GvyUe%D^QFuUFii_hB12ZO|gGbcV)G8|~+LKjk>79C8GIqpo6NBwu
z9sgMT;~|ro`Hmi~@?4uJ9r4ZqTt9Z~7=YRB+qXd|-TeHt^T#v#3pe+g`YgRr(OqT#9nXaq0|Ulk;7Vb)
zM9d?ai0}8IJ~cG-_8JIJEidDy=&tu(hCv-vmGH@vbO=wq6pBWpiQd%47bh~cVkf4i
zus^C9KsG);Co)dTvK`zk5c3X|I_ghZ>P%DP4O9KQB0vp@U{9IV_>R@xV`e>+d%fIw
z``eVy#-dTByM2UNj_p%GZi*FB7uIh6$7$mul}T6eNU8ncHDPJ`?ec150sjmT2yUCp
z!`l9NSP2l8s}w+VRgs&$5jH$yP|!KMEpMaZ&qzmo2sRyXAi*I6vR<)~)o$EU-p
z26{&mkJRqcD8R{Y0z4qPKn3iq$&UJR@$h8-jr6Ols}EN)GBZW6kX-}^1^uW>)9>Es
zC4>KDn5^g_)|gtj=mC1NuwUTc`tZdzfbNEYuLyQBA@}bWISd<90H`0~i7Z>)S$Yx@
z68`@FRAyK_TOTo_)39M%RPgW~!PHc9x
z+d!C5Y}=cieey>Z_iHjU=E{|KpsdC}hOjz7souX8$n~#(HMg|T_3gB80Zw9X@cVXN
zunfxo!H6g(2dnAUSXS;+JM%gDNuCpr1yy1jKq-Yek2C}_`*RoyOIx-lfXWaztErMF
zF(YH2PdKr9zYk&ty=Dx>#wuQwLZycxdyMzdG1;+}y0Nppo~e_Vy+#LuqY%1*xZW(X
z#-DLtG&D4nyWJc~o`frYl@^A3IjGHK_s;Mk2VZt%bL&q2j8d$Y;NKX_3914tl5x_{
z2-5H=|HK~TECSyA-}ew`O3~}-?zS7Ll2=er5D*v}4?%5^NCbZCu{4uM?as?
zNs#NT^jHCNaYX8l-Dr)HsHoQD5d>-MA|E0`(dk0hZmo_(p$rXOhjbN!84&wnbg2Rj
z91|0hZ&JEk&us>pIuo6ZsdNV>Yi(@ogXr>aO$R}jwjln?>kA9vY$)aH!o`*y{C}_d
z%*>1kmXV2RA>4I&s2{wh_fhEPkPO`q+1c4>4KGj6ZdB)-D?dL!&HRNQ}b`MWaDOftwjKG6w1PG@~>nPd1sAg=Ib*q~>Qk8Ne9*7I?Bp
z_|tWOm!+opqs6uc)ED1fG2{n7z$NjshX;hvO<%u$rMKB^=Oh$ZXJ_Z~^74@*M-)G?
zB4t@td}A+PzJ$`Zw6qKfp&xy`y&VQi@;p{XjOpEw(8F*|g8*wkR3;%LBqSgpAR`mq
z`#pZz1Cb}P<#zwSK&vmr;*@+7F#O)$-VmFCp8*M7xbyX8r_~S?Hpl{CghY=Kd7JLv
zGd-(+PV4l9-Ff=-X;&8-0via8E5S!~r5P^*ZGa9B4+~owEX^lI3%+Wb287?4HV5hm
z;o!TtQPd4Q|1u&1tl~h4J@3!-*Z9Q5mw>|2QpZuSQ~AouH$St1OuVh^cqvU1y(%hlit^M@L7=Le{nZRGnmHvFaRapf^2@Vu#@~zyIDi
zIA|g)4Vr9z-ewLX_SUxd)WWD+&DI3#oS3#0PnbqlU|`_ey#RDKr`It1B6^3Xz`VmK9ClMsiqN&1QV3~&dA9b=J&$Rc`Wp33zHz_>>&`;
zS8N7qX(Vw+#}yg-f%_pLKAxVgD&sg9i^FFuM@K(bmyX$}bOK=H*qs
zm>qq_V>uxwX8{@$8*-YSS_}?W((>g3$oS+)bdEuOG=`84a0i*wMO9Vf-QmWjCWxa^
z(l(Jqoa%K2S;&!G+}!-u>bcwQ6i)5p^n3En0){hPf{oNqSXTSqUkn
zRIHYFH4PhM`jWrvIzaIJaAhgUv0zUh&eUt_pqZIjrpU6RsBzI{VYk(>b92YES=rg`
z`|_SVVZnAQtW=$l%aX4l&x>HMYG`OsUu=%}ba;y!I1!4a!H79r=
zry(I~SFd(MZk9MP$H*&V_vrCsVR7-@#lj8WpzxvdShauLQobVbz^A*3m86IXBHHU5Ab
zg0{4@G&~-UohfPsl5%lz(M>!f4W9;M0#kw}a!BsS3NUprReSQ}35YsK955J+Wk(Vp
zA7A3jmtEQVB6DtSZr}kR$b`sAlhZo-H_hlz_4TBs!A%-vCI9=>EeRH-?CxZ`hxB{n
zT)?%I6oG{o6B8EL?m2uWvjHXq{P#VkeKLywI(*m@Yy_0ckaLSz?;3mJ;!3v8d~=it
zm!MV|smBEJ4)JPixwEq~SnkN^=sS|J2~!>T4wYR+5s?=1SQyt`H#cxMR;H#S;4L9v
zEQOR6@U;Dv#075yuG~!(K$04GrW0U=U?K%ky~^&+Is|FynZ%B=OlW;g35K|<7*L_$K6NmCC
zdiYusA03^M@Ks_g2U6}_fcq|yxIc}Jvm;s9*z7#t!mWeXe-YP>E-o$xf$FpRejjw5
zftHpQ2!(~@ZyQjyCxyI%zCuD5g@$HLJmY3#XxIn%oD~_Tr0=H})pq~%n-
zz9MTqBcoV7#j4cElOiI6FfoLOHree^Jay`nqM|Q6QNhQ!o6AGx@iO)-92}=aMH5b2
zza(vc>|s-Yu|Qo=P|!oQZ|m!HdA~v{oRBcDl;jD6+UNr&0)9xGotesqk?z5{pR_BN
zN(MorbE1^({Cd5EPXiZ~l=RrigzDJ7gYgig-kk)3zIS8stZN12d1-3l#ypBlzd-~k
zAaK^*a6RvOc>#!rn+?yRpwoLO3DLVW=7KwgK;IJV8Iq0
zn=CjFC{WP6on#(PjV$;&JJ0D^GK#sZeZl3Yb~o06TawzZ{&AwZo
zYEX$phjNRT)KIo(l0~qGL=6QhvtyrxhLXIgk-~cEAw_3P9flbh8KGfvS8&F~%|^7r
z*5+o2bc+o|Rnyk;1E@Li@q-{o($z4UY2{7L&CYl4dcj8LsqC}!yGo(c_i~}!xj@)r
z62S(tfGG6q*RNry3*+mq$~bdsVHVtItyfzjIr*52A;hQ}!m!lP;*jJf>TG`E(uHi`
zlD9#N+?BvluNgkHX)08h^?;1MjhbPEi|
zALI}g!EXJ!uw|FO>>3se60Demen@+v*q
Vv(Hj`0)~r-`X!x*Pf
literal 0
HcmV?d00001
From d6b372b74e33d9a795086523392c22d1a23ac963 Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Tue, 30 Nov 2021 17:14:44 +0100
Subject: [PATCH 094/146] Fix barnsley rust code path (#952)
---
contents/barnsley/barnsley.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contents/barnsley/barnsley.md b/contents/barnsley/barnsley.md
index 6b2d6b3bf..625d72e8e 100644
--- a/contents/barnsley/barnsley.md
+++ b/contents/barnsley/barnsley.md
@@ -126,7 +126,7 @@ The biggest differences between the two code implementations is that the Barnsle
{% sample lang="jl" %}
[import, lang:"julia"](code/julia/barnsley.jl)
{% sample lang="rs" %}
-[import, lang:"rust"](code/rust/src/main.rs)
+[import, lang:"rust"](code/rust/barnsley.rs)
{% sample lang="cpp" %}
[import, lang:"cpp"](code/cpp/barnsley.cpp)
{% sample lang="c" %}
From cf655b059534071cef5d66a5507586534b45cef1 Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Wed, 1 Dec 2021 15:16:06 +0100
Subject: [PATCH 095/146] Fix warnings on size_t to int conversions (#933)
---
contents/tree_traversal/code/cpp/tree_example.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/contents/tree_traversal/code/cpp/tree_example.cpp b/contents/tree_traversal/code/cpp/tree_example.cpp
index 71a84c686..90271b58d 100644
--- a/contents/tree_traversal/code/cpp/tree_example.cpp
+++ b/contents/tree_traversal/code/cpp/tree_example.cpp
@@ -11,7 +11,7 @@ using std::size_t;
struct node {
std::vector children;
- int value;
+ size_t value;
};
// Simple recursive scheme for DFS
From d51c940156603080e03c7331141e4c9cbbb623a1 Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Wed, 1 Dec 2021 18:23:05 +0100
Subject: [PATCH 096/146] Fix import of coconut in flood_fill.md (#951)
Fix import of coconut in flood_fill.md
---
contents/flood_fill/flood_fill.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/contents/flood_fill/flood_fill.md b/contents/flood_fill/flood_fill.md
index 62348f107..3fb4f239c 100644
--- a/contents/flood_fill/flood_fill.md
+++ b/contents/flood_fill/flood_fill.md
@@ -95,7 +95,7 @@ In code, this might look like this:
{% sample lang="py" %}
[import:10-25, lang="python"](code/python/flood_fill.py)
{% sample lang="coco" %}
-[import:15-19, lang="coconut"](code/coconut/flood_fill.coco)
+[import:15-20, lang="coconut"](code/coconut/flood_fill.coco)
{% endmethod %}
@@ -117,7 +117,7 @@ In code, it might look like this:
{% sample lang="py" %}
[import:55-63, lang="python"](code/python/flood_fill.py)
{% sample lang="coco" %}
-[import:54-63, lang:"coconut"](code/coconut/flood_fill.coco)
+[import:52-61, lang:"coconut"](code/coconut/flood_fill.coco)
{% endmethod %}
The above code continues recursing through available neighbors as long as neighbors exist, and this should work so long as we are adding the correct set of neighbors.
@@ -179,7 +179,7 @@ The code would look something like this:
{% sample lang="py" %}
[import:38-53, lang="python"](code/python/flood_fill.py)
{% sample lang="coco" %}
-[import:37-51, lang:"coconut"](code/coconut/flood_fill.coco)
+[import:36-49, lang:"coconut"](code/coconut/flood_fill.coco)
{% endmethod %}
Now, there is a small trick in this code that must be considered to make sure it runs optimally.
From 67a5cf027e3586d081b5d5fc5c9d09995c3ba14b Mon Sep 17 00:00:00 2001
From: stormofice <58337328+stormofice@users.noreply.github.com>
Date: Wed, 1 Dec 2021 20:55:24 +0100
Subject: [PATCH 097/146] IFS: Standardize output files (#961)
* Output 10000 points instead of 1000 in C implementation
* Change output file from "out.dat" to "sierpinski.dat" in lisp
* Change output file from "out.dat" to "sierpinski.dat" in Haskell
* Introduce constant for the amount of points to generate
Co-authored-by: James Schloss
---
contents/IFS/code/c/IFS.c | 9 +++++----
contents/IFS/code/clisp/ifs.lisp | 2 +-
contents/IFS/code/haskell/IFS.hs | 2 +-
3 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/contents/IFS/code/c/IFS.c b/contents/IFS/code/c/IFS.c
index 99c4826be..e4aab3b50 100644
--- a/contents/IFS/code/c/IFS.c
+++ b/contents/IFS/code/c/IFS.c
@@ -29,16 +29,18 @@ void chaos_game(struct point *in, size_t in_n, struct point *out,
}
int main() {
+ const int point_count = 10000;
+
struct point shape_points [3] = {{0.0,0.0}, {0.5,sqrt(0.75)}, {1.0,0.0}};
- struct point out_points[1000];
+ struct point out_points[point_count];
srand(time(NULL));
- chaos_game(shape_points, 3, out_points, 1000);
+ chaos_game(shape_points, 3, out_points, point_count);
FILE *fp = fopen("sierpinksi.dat", "w+");
- for (int i = 0; i < 1000; ++i) {
+ for (int i = 0; i < point_count; ++i) {
fprintf(fp, "%f\t%f\n", out_points[i].x, out_points[i].y);
}
@@ -46,4 +48,3 @@ int main() {
return 0;
}
-
diff --git a/contents/IFS/code/clisp/ifs.lisp b/contents/IFS/code/clisp/ifs.lisp
index 4354ab54b..c9fc0e432 100644
--- a/contents/IFS/code/clisp/ifs.lisp
+++ b/contents/IFS/code/clisp/ifs.lisp
@@ -21,7 +21,7 @@
`((0 0) (0.5 ,(sqrt 0.75)) (1 0))))
;; output the data to the "out.dat" file
-(with-open-file (out "out.dat" :direction :output :if-exists :supersede)
+(with-open-file (out "sierpinski.dat" :direction :output :if-exists :supersede)
(flet ((format-point (p)
;; this is not very clean, but it's the simplest way to insert a tab into a string.
(format nil "~f~c~f" (point-x p) #\tab (point-y p))))
diff --git a/contents/IFS/code/haskell/IFS.hs b/contents/IFS/code/haskell/IFS.hs
index 9e8f4ef70..41d8b4c9a 100644
--- a/contents/IFS/code/haskell/IFS.hs
+++ b/contents/IFS/code/haskell/IFS.hs
@@ -27,4 +27,4 @@ main = do
points = chaosGame g 10000 sierpinski
showPoint (Point x y) = show x ++ "\t" ++ show y
- writeFile "out.dat" $ intercalate "\n" $ map showPoint points
+ writeFile "sierpinski.dat" $ intercalate "\n" $ map showPoint points
From 3bbc549cdea4c71e66a15b8dec61a9c7968b521f Mon Sep 17 00:00:00 2001
From: Dimitri Belopopsky
Date: Thu, 2 Dec 2021 16:38:38 +0100
Subject: [PATCH 098/146] Fix warning on MSVC for barnsley C++ code (#943)
Co-authored-by: James Schloss
---
contents/barnsley/code/cpp/barnsley.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/contents/barnsley/code/cpp/barnsley.cpp b/contents/barnsley/code/cpp/barnsley.cpp
index 88fb24766..491d6bd51 100644
--- a/contents/barnsley/code/cpp/barnsley.cpp
+++ b/contents/barnsley/code/cpp/barnsley.cpp
@@ -75,6 +75,7 @@ auto select_array(
rnd -= probabilities[i];
}
assert(!static_cast("check if probabilities adding up to 1"));
+ return hutchinson_op[0];
}
// This is a general function to simulate a chaos game
From fca9911a7c1cf44fd4bc79e850e021a6c385f3eb Mon Sep 17 00:00:00 2001
From: PaddyKe <34421580+PaddyKe@users.noreply.github.com>
Date: Thu, 2 Dec 2021 16:52:03 +0100
Subject: [PATCH 099/146] Added Iterated function system in PowerShell (#895)
* implemented IFS in PowerShell
* fixed typo
Co-authored-by: James Schloss
---
contents/IFS/IFS.md | 4 ++++
contents/IFS/code/powershell/IFS.ps1 | 34 ++++++++++++++++++++++++++++
2 files changed, 38 insertions(+)
create mode 100644 contents/IFS/code/powershell/IFS.ps1
diff --git a/contents/IFS/IFS.md b/contents/IFS/IFS.md
index cd503ae46..f7d017e36 100644
--- a/contents/IFS/IFS.md
+++ b/contents/IFS/IFS.md
@@ -146,6 +146,8 @@ Here, instead of tracking children of children, we track a single individual tha
[import:4-16, lang:"coconut"](code/coconut/IFS.coco)
{% sample lang="java" %}
[import:16-39, lang:"java"](code/java/IFS.java)
+{% sample lang="ps1" %}
+[import:2-19, lang:"powershell"](code/powershell/IFS.ps1)
{% endmethod %}
If we set the initial point to the on the equilateral triangle we saw before, we can see the Sierpinski triangle again after a few thousand iterations, as shown below:
@@ -232,6 +234,8 @@ In addition, we have written the chaos game code to take in a set of points so t
[import, lang:"coconut"](code/coconut/IFS.coco)
{%sample lang="java" %}
[import, lang:"java"](code/java/IFS.java)
+{% sample lang="ps1" %}
+[import, lang:"powershell"](code/powershell/IFS.ps1)
{% endmethod %}
### Bibliography
diff --git a/contents/IFS/code/powershell/IFS.ps1 b/contents/IFS/code/powershell/IFS.ps1
new file mode 100644
index 000000000..086c80072
--- /dev/null
+++ b/contents/IFS/code/powershell/IFS.ps1
@@ -0,0 +1,34 @@
+# This function simulates a "chaos game"
+function Simulate-ChaosGame($n, $shapePoints) {
+ $outputPoints = New-Object System.Collections.ArrayList
+
+ # Initialize the starting point
+ $point = @($(Get-Random -Minimum 0.0 -Maximum 1.0), $(Get-Random -Minimum 0.0 -Maximum 1.0))
+
+ for ($i = 0; $i -lt $n; $i++) {
+ $outputPoints.add($point) | Out-Null
+ $temp = $shapePoints[$(Get-Random -Maximum $shapePoints.Count)]
+
+ $point = @(
+ 0.5 * ($point[0] + $temp[0])
+ 0.5 * ($point[1] + $temp[1])
+ )
+ }
+
+ return $outputPoints
+}
+
+
+# This will generate a Sierpinski triangle with a chaos game of n points for an
+# initial triangle with three points on the vertices of an equilateral triangle:
+# A = (0.0, 0.0)
+# B = (0.5, sqrt(0.75))
+# C = (1.0, 0.0)
+# It will output the file sierpinski.dat, which can be plotted after
+$shapePoints = @(
+ @(0.0, 0.0),
+ @(0.5, [math]::sqrt(0.75)),
+ @(1.0, 0.0)
+)
+
+Simulate-ChaosGame -n 10000 -shapePoints $shapePoints | % { "$($_[0])`t$($_[1])" } | Out-File -Path "sierpinski.dat"
From a3276bedd94ea7cee587bb565c351c405e9b86b9 Mon Sep 17 00:00:00 2001
From: PaddyKe <34421580+PaddyKe@users.noreply.github.com>
Date: Thu, 2 Dec 2021 16:54:26 +0100
Subject: [PATCH 100/146] Add Approximate counting in Java (#898)
* added approximative counting in java
* added code examples to markdown files
* fixed typo
* fixed indentation
* fixed typos
* fixed printed comments
* added failed message
* Update contents/approximate_counting/code/java/ApproximateCounting.java
Co-authored-by: stormofice <58337328+stormofice@users.noreply.github.com>
Co-authored-by: James Schloss
Co-authored-by: stormofice <58337328+stormofice@users.noreply.github.com>
---
.../approximate_counting.md | 2 +
.../code/java/ApproximateCounting.java | 85 +++++++++++++++++++
2 files changed, 87 insertions(+)
create mode 100644 contents/approximate_counting/code/java/ApproximateCounting.java
diff --git a/contents/approximate_counting/approximate_counting.md b/contents/approximate_counting/approximate_counting.md
index 5e06e43b5..e5b7c1f5e 100644
--- a/contents/approximate_counting/approximate_counting.md
+++ b/contents/approximate_counting/approximate_counting.md
@@ -366,6 +366,8 @@ As we do not have any objects to count, we will instead simulate the counting wi
[import, lang:"cpp"](code/cpp/approximate_counting.cpp)
{% sample lang="python" %}
[import, lang:"python"](code/python/approximate_counting.py)
+{% sample lang="java" %}
+[import, lang:"java"](code/java/ApproximateCounting.java)
{% endmethod %}
### Bibliography
diff --git a/contents/approximate_counting/code/java/ApproximateCounting.java b/contents/approximate_counting/code/java/ApproximateCounting.java
new file mode 100644
index 000000000..2dd49c0f0
--- /dev/null
+++ b/contents/approximate_counting/code/java/ApproximateCounting.java
@@ -0,0 +1,85 @@
+import java.lang.Math;
+import java.util.stream.DoubleStream;
+
+public class ApproximateCounting {
+
+ /*
+ * This function taks
+ * - v: value in register
+ * - a: a scaling value for the logarithm based on Morris's paper
+ * It returns the approximate count
+ */
+ static double n(double v, double a) {
+ return a * (Math.pow(1 + 1 / a, v) - 1);
+ }
+
+
+ /*
+ * This function takes
+ * - v: value in register
+ * - a: a scaling value for the logarithm based on Morris's paper
+ * It returns the new value for v
+ */
+ static double increment(double v, double a) {
+ double delta = 1 / (n(v + 1, a) - n(v, a));
+
+ if (Math.random() <= delta) {
+ return v + 1;
+ } else {
+ return v;
+ }
+ }
+
+
+
+ /*
+ * This function takes
+ * - v: value in register
+ * - a: a scaling value for the logarithm based on Morris's paper
+ * It returns the new value for v
+ */
+ static double approximateCount(int nItems, double a) {
+ double v = 0;
+
+ for (int i = 0; i < nItems; i++) {
+ v = increment(v, a);
+ }
+
+ return n(v, a);
+ }
+
+ /*
+ * This function takes
+ * - nTrials: the number of counting trails
+ * - nItems: the number of items to count
+ * - a: a scaling value for the logarithm based on Morris's paper
+ * - threshold: the maximum percent error allowed
+ * It terminates the program on failure
+ */
+ static void testApproximateCount(int nTrials, int nItems, double a, double threshold) {
+ double avg = DoubleStream.generate(() -> approximateCount(nItems, a))
+ .limit(nTrials)
+ .average()
+ .getAsDouble();
+
+ if (Math.abs((avg - nItems) / nItems) < threshold) {
+ System.out.println("passed");
+ } else {
+ System.out.println("failed");
+ }
+ }
+
+
+ public static void main(String args[]) {
+ System.out.println("[#]\nCounting Tests, 100 trials");
+ System.out.println("[#]\ntesting 1,000, a = 30, 10% error");
+ testApproximateCount(100, 1_000, 30, 0.1);
+
+ System.out.println("[#]\ntesting 12,345, a = 10, 10% error");
+ testApproximateCount(100, 12_345, 10, 0.1);
+
+ System.out.println("[#]\ntesting 222,222, a = 0.5, 20% error");
+ testApproximateCount(100, 222_222, 0.5, 0.2);
+ }
+
+}
From aa83fecb8fa4cd5508b362b62af6fa9f3b6a1e64 Mon Sep 17 00:00:00 2001
From: PeanutbutterWarrior
<50717143+PeanutbutterWarrior@users.noreply.github.com>
Date: Thu, 2 Dec 2021 16:18:34 +0000
Subject: [PATCH 101/146] Implement Stacks and Queues in Rust. (#924)
* Implement Stack
* Implement Queue
* Update markdown page
* Add comments with output of prints
* Use equivalent methods instead of reimplementing them
* Add SConscript file
Co-authored-by: James Schloss
---
CONTRIBUTORS.md | 5 ++-
contents/stacks_and_queues/code/rust/Queue.rs | 43 +++++++++++++++++++
.../stacks_and_queues/code/rust/SConscript | 10 +++++
contents/stacks_and_queues/code/rust/Stack.rs | 41 ++++++++++++++++++
.../stacks_and_queues/stacks_and_queues.md | 4 ++
5 files changed, 101 insertions(+), 2 deletions(-)
create mode 100644 contents/stacks_and_queues/code/rust/Queue.rs
create mode 100644 contents/stacks_and_queues/code/rust/SConscript
create mode 100644 contents/stacks_and_queues/code/rust/Stack.rs
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 82f3c173a..fc3113ecc 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -51,7 +51,7 @@ This file lists everyone, who contributed to this repo and wanted to show up her
- Vincent Zalzal
- Jonathan D B Van Schenck
- James Goytia
-- Sammy Plat
+- Sammy Plat
- Jonathan Dönszelmann
- Ishaan Verma
- Delphi1024
@@ -60,4 +60,5 @@ This file lists everyone, who contributed to this repo and wanted to show up her
- Ridham177
- Hugo Salou
- Dimitri Belopopsky
-+ Henrik Abel Christensen
+- Henrik Abel Christensen
+- Peanutbutter_Warrior
diff --git a/contents/stacks_and_queues/code/rust/Queue.rs b/contents/stacks_and_queues/code/rust/Queue.rs
new file mode 100644
index 000000000..0f432e621
--- /dev/null
+++ b/contents/stacks_and_queues/code/rust/Queue.rs
@@ -0,0 +1,43 @@
+use std::collections::VecDeque;
+
+struct Queue {
+ list: VecDeque
+}
+
+impl Queue {
+ fn new() -> Self {
+ Queue{
+ list: VecDeque::new(),
+ }
+ }
+
+ // Note that this returns a reference to the value
+ // This is in contrast to dequeue which gives ownership of the value
+ fn front(&self) -> Option<&T> {
+ self.list.front()
+ }
+
+ fn dequeue(&mut self) -> Option {
+ self.list.pop_front()
+ }
+
+ fn enqueue(&mut self, item: T) {
+ self.list.push_back(item);
+ }
+
+ fn size(&self) -> usize {
+ self.list.len()
+ }
+}
+
+fn main() {
+ let mut i32queue = Queue::new();
+
+ i32queue.enqueue(4);
+ i32queue.enqueue(5);
+ i32queue.enqueue(6);
+
+ println!("{:?}", i32queue.dequeue().unwrap()); // 4
+ println!("{:?}", i32queue.size()); // 2
+ println!("{:?}", i32queue.front().unwrap()); // 5
+}
diff --git a/contents/stacks_and_queues/code/rust/SConscript b/contents/stacks_and_queues/code/rust/SConscript
new file mode 100644
index 000000000..0c3f15913
--- /dev/null
+++ b/contents/stacks_and_queues/code/rust/SConscript
@@ -0,0 +1,10 @@
+Import('*')
+from pathlib import Path
+
+dirname = Path.cwd().parents[1].stem
+
+env.rustc(f'#/build/rust/stack', '#/contents/stacks_and_queues/code/rust/Stack.rs')
+env.Clean('rust', f'#/build/rust/stack.pdb')
+
+env.rustc(f'#/build/rust/queue', '#/contents/stacks_and_queues/code/rust/Queue.rs')
+env.Clean('rust', f'#/build/rust/queue.pdb')
\ No newline at end of file
diff --git a/contents/stacks_and_queues/code/rust/Stack.rs b/contents/stacks_and_queues/code/rust/Stack.rs
new file mode 100644
index 000000000..13010c3f0
--- /dev/null
+++ b/contents/stacks_and_queues/code/rust/Stack.rs
@@ -0,0 +1,41 @@
+struct Stack {
+ list: Vec
+}
+
+impl Stack {
+ fn new() -> Self {
+ Stack {
+ list: Vec::new(),
+ }
+ }
+
+ // Note that this returns a reference to the value
+ // This is in contrast to pop which gives ownership of the value
+ fn top(&self) -> Option<&T> {
+ self.list.last()
+ }
+
+ fn pop(&mut self) -> Option {
+ self.list.pop()
+ }
+
+ fn push(&mut self, item: T) {
+ self.list.push(item);
+ }
+
+ fn size(&self) -> usize {
+ self.list.len()
+ }
+}
+
+fn main() {
+ let mut i32stack: Stack = Stack::new();
+
+ i32stack.push(4);
+ i32stack.push(5);
+ i32stack.push(6);
+
+ println!("{:?}", i32stack.pop().unwrap()); // 6
+ println!("{:?}", i32stack.size()); // 2
+ println!("{:?}", i32stack.top().unwrap()); // 5
+}
diff --git a/contents/stacks_and_queues/stacks_and_queues.md b/contents/stacks_and_queues/stacks_and_queues.md
index 5d637deb3..a3c46b478 100644
--- a/contents/stacks_and_queues/stacks_and_queues.md
+++ b/contents/stacks_and_queues/stacks_and_queues.md
@@ -20,6 +20,8 @@ Here is a simple implementation of a stack:
[import, lang:"typescript"](code/typescript/stack.ts)
{% sample lang="java" %}
[import, lang:"java"](code/java/Stack.java)
+{% sample lang="rust" %}
+[import, lang:"rust"](code/rust/Stack.rs)
{% endmethod %}
Here is a simple implementation of a queue:
@@ -28,6 +30,8 @@ Here is a simple implementation of a queue:
[import, lang:"typescript"](code/typescript/queue.ts)
{% sample lang="java" %}
[import, lang:"java" ](code/java/Queue.java)
+{% sample lang="rust" %}
+[import, lang:"rust" ](code/rust/Queue.rs)
{% endmethod %}
From ffaa8901c27607f25a868a12837d2b27671199cf Mon Sep 17 00:00:00 2001
From: Nicholas Tindle
Date: Thu, 2 Dec 2021 13:01:44 -0600
Subject: [PATCH 102/146] Use Scons in CI with container (#959)
Use Scons with the container
Co-authored-by: Sammy Plat
Co-authored-by: James Schloss
---
.github/workflows/build.yml | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 2d25ca4d3..3ed45c6c1 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -4,6 +4,12 @@ on: pull_request
jobs:
build:
runs-on: ubuntu-latest
+ container:
+ options: --entrypoint /bin/bash --user 0
+ image: ghcr.io/algorithm-archivists/aaa-langs:latest
+ defaults:
+ run:
+ shell: bash --rcfile /root/.bashrc -eo pipefail {0}
steps:
- name: Checkout
uses: actions/checkout@v2
@@ -14,3 +20,10 @@ jobs:
run: |
npm install
npx honkit build
+
+ - name: Initalize cargo and run SCons
+ env:
+ HOME: /root
+ run: |
+ . "$HOME/.cargo/env"
+ scons -Q
From 05e97580b2ee00b0dae20c94a8e7c51352d064ef Mon Sep 17 00:00:00 2001
From: Shudipto <32040453+shudipto-amin@users.noreply.github.com>
Date: Fri, 3 Dec 2021 08:25:04 -0500
Subject: [PATCH 103/146] New chapter "Metropolis" with Python Implementation
(#929)
* Add new chapter: metropolis_hastings; in python
* Add markdown and python files for metropolis
* Add image for metropolis
* Update .gitignore, SUMMARY.md, and metropolis
* Untrack .ipynb_checkpoints
* Untrack ipynb_checkpoints
* Fix algorithm steps list
* Really fix markdown list
* Add plot of P to chapter
* Add metropolis animation and update plot of P(x)
* Add minor update to chapter text
* Generate gif and mp4 for random walk
* Complete first draft!
* Final version before Pull Request
* Add metropolis citation
* Remove unnecessary lines from code and bib file
* Fix display of code in md
* Fix random walk capitalization.
* Apply Amaras' suggestions from code review
This commit makes minor edits which resolve conflicts with PEP8 and improve readability of code.
It also makes chapter sub-chapter of Monte Carlo.
Co-authored-by: James Schloss
Co-authored-by: Sammy Plat
* Fix the code import lines in md file.
* Change to in metropolis.py
* Add probability section to metropolis.md
However, this is temporary, as this section needs to go into a separate chapter.
* Move Probability section in metropolis to own chapter.
* Fix SUMMARY.md spelling mistake from previous commit
* Add figures for probability distribution chapter
* Update image of normal distribution
* Finish first draft of probability chapter
* Minor edits to distributions.md.
* "Minor changes to distributions.md"
* Complete the Example/Application section of metropolis.
* Address most issues in review of PR#929
* Application sections created.
* g() definition moved up to a better place
* More discussion on g.
* Missing citations provided
* Clarity provided (hopefully)
* Add image of 1D_particles
* Update citations in md file
* Add testing function to metropolis python code.
Also modifies markdown to describe test.
Also adds citation for RMSD.
* Numpyfy metropolis f function and fix errors.
* Implement generator to iterate.
* Reformat output of test and nrmsd error reporting.
* Add description of video and fix code display.
* Update contents/probability/distributions/distributions.md
Co-authored-by: James Schloss
* Update contents/probability/distributions/distributions.md
Co-authored-by: James Schloss
* Update contents/probability/distributions/distributions.md
Co-authored-by: James Schloss
* Update contents/probability/distributions/distributions.md
Co-authored-by: James Schloss
* Update contents/probability/distributions/distributions.md
Co-authored-by: James Schloss
* Update contents/probability/distributions/distributions.md
Co-authored-by: James Schloss
* Update contents/probability/distributions/distributions.md
Co-authored-by: James Schloss
* Update contents/probability/distributions/distributions.md
Co-authored-by: James Schloss
* Update contents/probability/distributions/distributions.md
Co-authored-by: James Schloss
* Put sentences in `metropolis.md` on separate lines.
* Put sentences in distributions.md chapter on separate lines.
* Addresses issues raised by Leios' 1st review of probability chapter.
* Adds intro to beginning.
* Fixes plurality of die.
* Clarifies some notation in discrete section.
* Removes explanation of calculus.
* Other minor edits.
* Add minor edits.
* Update contents/metropolis/metropolis.md title
Co-authored-by: James Schloss
* Simplify intro to contents/metropolis/metropolis.md
Co-authored-by: James Schloss
* Minor formatting to contents/metropolis/metropolis.md
Co-authored-by: James Schloss
* Fix spelling contents/metropolis/metropolis.md
Co-authored-by: James Schloss
* Simplify line 71 of contents/metropolis/metropolis.md
Co-authored-by: James Schloss
* Update contents/metropolis/metropolis.md
Co-authored-by: James Schloss
* Update example application in metropolis according to Leios comments.
* Minor edit: contents/probability/distributions/distributions.md
Co-authored-by: James Schloss