Skip to content

Commit 608c54d

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents a9466b6 + 64a9d0f commit 608c54d

File tree

124 files changed

+2504
-1521
lines changed

Some content is hidden

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

124 files changed

+2504
-1521
lines changed

.editorconfig

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
root = true
22

3-
# This file
4-
[.editorconfig]
5-
trim_trailing_whitespace = true
6-
insert_final_newline = true
7-
8-
# Pretty much everything should trim whitespace and have a final EOL
9-
[*.{c,clj,cpp,cs,css,elm,go,hs,html,jl,js,md,py,rs}]
3+
# Base for all text files
4+
[*]
105
trim_trailing_whitespace = true
116
insert_final_newline = true
7+
end_of_line = lf
128

139
# C
1410
[*.c]
@@ -35,6 +31,11 @@ indent_size = 4
3531
indent_style = space
3632
indent_size = 2
3733

34+
# D
35+
[*.d]
36+
indent_style = space
37+
indent_size = 4
38+
3839
# Elm
3940
[*.elm]
4041
indent_style = space
@@ -54,6 +55,11 @@ indent_size = 2
5455
indent_style = space
5556
indent_size = 2
5657

58+
# Java
59+
[*.java]
60+
indent_style = space
61+
indent_size = 4
62+
5763
# Julia
5864
[*.jl]
5965
indent_style = space
@@ -69,6 +75,11 @@ indent_size = 2
6975
indent_style = space
7076
indent_size = 2
7177

78+
# OCAML
79+
[*.ml]
80+
indent_style = space
81+
indent_size = 2
82+
7283
# Python
7384
[*.py]
7485
indent_style = space

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Force all text files to have LF line endings
2+
* text=auto eol=lf

CONTRIBUTORS.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ Nicole Mazzuca
33
Marius Becker
44
Gathros
55
Jeremie Gillet (- Jie -)
6-
Salim Khatib
6+
Salim Khatib
7+
Hitesh C
8+
Maxime Dherbécourt
9+
Jess 3Jane
10+
Pen Pal

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
# The Arcane Algorithm Archive
2-
The Arcane Algorithm Archive is a collaborative effort to create a guide for all important algorithms in all languages.
2+
The Arcane Algorithm Archive is a collaborative effort to create a guide for all important algorithms in all languages.
33
This goal is obviously too ambitious for a book of any size, but it is a great project to learn from and work on and will hopefully become an incredible resource for programmers in the future.
44
The book can be found here: https://www.algorithm-archive.org/.
55
The github repository can be found here: https://github.com/algorithm-archivists/algorithm-archive.
66
Most algorithms have been covered on the youtube channel LeiosOS: https://www.youtube.com/user/LeiosOS
7-
and livecoded on Twitch: https://www.twitch.tv/simuleios
7+
and livecoded on Twitch: https://www.twitch.tv/simuleios.
8+
If you would like to communicate more directly, please feel free to go to our discord: https://discord.gg/Pr2E9S6.
89

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

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

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* [Tree Traversal](chapters/tree_traversal/tree_traversal.md)
2929
* [Euclidean Algorithm](chapters/euclidean_algorithm/euclidean.md)
3030
* [Multiplication](chapters/multiplication/multiplication.md)
31+
* [Monte Carlo](chapters/monte_carlo/monte_carlo.md)
3132
* [Matrix Methods](chapters/matrix_methods/matrix_methods.md)
3233
* [Gaussian Elimination](chapters/matrix_methods/gaussian_elimination/gaussian_elimination.md)
3334
* [Thomas Algorithm](chapters/matrix_methods/thomas/thomas.md)

TODO.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ I'll try to keep this list updated as I write more sections
2222

2323
Here are points of discussion that need to be had about the Algorithm Archive before it gets too big and becomes too difficult to revise everything
2424

25-
* **Should community-submitted code be clean or efficeint?** When it comes to writing code, I often feel readability is the most important factor to keep in mind; however, with the code submitted to this archive, there will be psudocode available to guide new folks through the process of writing the algorithm for the first time. For this reason, it might be best for the community to submit the most efficient code they can write in their own languages, commenting in any tricks to improve performance.
26-
* **Is the current method of writing optimal?** When I originally envisioned this project, I thought that I would do all the writing and the community would do (most of) the coding. That said, I am becoming more open to the idea of letting community members write for the Archive. The advantage to this is obvious: The book gets written faster. The disadvantage is also obvious: We lose focus and consistency throughout the book.
27-
* **We need a Logo.** I have no idea how to go about this. Maybe a logo contest at 16384 subscribers on youtube? The project will be large enough at that point to warrant a good logo. I really want something simple, though, like a [Trefoil Knot](https://en.wikipedia.org/wiki/Trefoil_knot#/media/File:Trefoil_knot_left.svg) or something. It kinda looks like 3 A's if you look at it the right way, and we'll definitely cover knot algorithms at some point because they are fascinating!
25+
* **Should community-submitted code be clean or efficient?** When it comes to writing code, I often feel readability is the most important factor to keep in mind; however, with the code submitted to this archive, there will be pseudocode available to guide new folks through the process of writing the algorithm for the first time. For this reason, it might be best for the community to submit the most efficient code they can write in their own languages, commenting in any tricks to improve performance.
26+
* **Is the current method of writing optimal?** When I originally envisioned this project, I thought that I would do all the writing and the community would do (most of) the coding. That said, I am becoming more open to the idea of letting community members write for the Archive. The advantage to this is obvious: The book gets written faster. The disadvantage is also obvious: We lose focus and consistency throughout the book.
27+
* **We need a Logo.** I have no idea how to go about this. Maybe a logo contest at 16384 subscribers on youtube? The project will be large enough at that point to warrant a good logo. I really want something simple, though, like a [Trefoil Knot](https://en.wikipedia.org/wiki/Trefoil_knot#/media/File:Trefoil_knot_left.svg) or something. It kinda looks like 3 A's if you look at it the right way, and we'll definitely cover knot algorithms at some point because they are fascinating!
2828

2929
Anyway, let me know what you think. I love the community we have here and appreciate all the conversations we've had so far!

book.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
{
2727
"lang": "cs",
28-
"name": "C#"
28+
"name": "C#"
2929
},
3030
{
3131
"lang": "cpp",
@@ -78,8 +78,12 @@
7878
{
7979
"lang": "LabVIEW",
8080
"name": "LabVIEW"
81+
},
82+
{
83+
"lang": "d",
84+
"name": "D"
8185
}
82-
86+
8387
],
8488
"split": false
8589
}

book_ace.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
},
1919
{
2020
"lang": "cs",
21-
"name": "C#"
21+
"name": "C#"
2222
},
2323
{
2424
"lang": "c",
25-
"name": "C"
25+
"name": "C"
2626
}
2727
],
28-
"split": true
28+
"split": true
2929
},
3030
"include-codeblock": {
3131
"template": "ace",

chapters/FFT/code/c/fft.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
#include <complex.h>
22
#include <math.h>
3+
#include <stdio.h>
34
#include <stdlib.h>
5+
#include <string.h>
46
#include <time.h>
5-
#include <stdio.h>
67

7-
#define PI 3.1415926535897932384626
8+
void dft(double complex *X, const size_t N) {
9+
double complex tmp[N];
10+
for (size_t i = 0; i < N; ++i) {
11+
tmp[i] = 0;
12+
for (size_t j = 0; j < N; ++j) {
13+
tmp[i] += X[j] * cexp(-2.0 * M_PI * I * j * i / N);
14+
}
15+
}
16+
17+
memcpy(X, tmp, N * sizeof(*X));
18+
}
819

920
void cooley_tukey(double complex *X, const size_t N) {
1021
if (N >= 2) {
@@ -21,38 +32,40 @@ void cooley_tukey(double complex *X, const size_t N) {
2132
cooley_tukey(X + N / 2, N / 2);
2233

2334
for (size_t i = 0; i < N / 2; ++i) {
24-
X[i + N / 2] = X[i] - cexp(-2.0 * I * PI * i / N) * X[i + N / 2];
35+
X[i + N / 2] = X[i] - cexp(-2.0 * I * M_PI * i / N) * X[i + N / 2];
2536
X[i] -= (X[i + N / 2]-X[i]);
2637
}
2738
}
2839
}
2940

3041
void bit_reverse(double complex *X, size_t N) {
31-
double complex temp;
32-
unsigned int b;
42+
for (int i = 0; i < N; ++i) {
43+
int n = i;
44+
int a = i;
45+
int count = (int)log2((double)N) - 1;
3346

34-
for (unsigned int i = 0; i < N; ++i) {
35-
b = i;
36-
b = (((b & 0xaaaaaaaa) >> 1) | ((b & 0x55555555) << 1));
37-
b = (((b & 0xcccccccc) >> 2) | ((b & 0x33333333) << 2));
38-
b = (((b & 0xf0f0f0f0) >> 4) | ((b & 0x0f0f0f0f) << 4));
39-
b = (((b & 0xff00ff00) >> 8) | ((b & 0x00ff00ff) << 8));
40-
b = ((b >> 16) | (b << 16)) >>
41-
(32 - (unsigned int) log2((double)N));
42-
if (b > i) {
43-
temp = X[b];
44-
X[b] = X[i];
45-
X[i] = temp;
46-
}
47+
n >>= 1;
48+
while (n > 0) {
49+
a = (a << 1) | (n & 1);
50+
count--;
51+
n >>= 1;
4752
}
53+
n = (a << count) & ((1 << (int)log2((double)N)) - 1);
54+
55+
if (n > i) {
56+
double complex tmp = X[i];
57+
X[i] = X[n];
58+
X[n] = tmp;
59+
}
60+
}
4861
}
4962

5063
void iterative_cooley_tukey(double complex *X, size_t N) {
5164
bit_reverse(X, N);
5265

5366
for (int i = 1; i <= log2((double)N); ++i) {
5467
int stride = pow(2, i);
55-
double complex w = cexp(-2.0 * I * PI / stride);
68+
double complex w = cexp(-2.0 * I * M_PI / stride);
5669
for (size_t j = 0; j < N; j += stride) {
5770
double complex v = 1.0;
5871
for (size_t k = 0; k < stride / 2; ++k) {

chapters/FFT/code/julia/fft.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function DFT(x)
55
# We want two vectors here for real space (n) and frequency space (k)
66
n = 0:N-1
77
k = n'
8-
transform_matrix = exp.(-2im * pi *n *k / N)
8+
transform_matrix = exp.(-2im*pi*n*k/N)
99
return transform_matrix*x
1010

1111
end
@@ -22,11 +22,10 @@ function cooley_tukey(x)
2222
x_even = x[2]
2323
end
2424
n = 0:N-1
25-
#n = n'
2625
half = div(N,2)
2726
factor = exp.(-2im*pi*n/N)
2827
return vcat(x_odd + x_even .* factor[1:half],
29-
x_odd - x_even .* factor[1:half])
28+
x_odd - x_even .* factor[1:half])
3029

3130
end
3231

@@ -85,7 +84,7 @@ function iterative_cooley_tukey(x)
8584
for k = 1:length(y)
8685
z[start_index+k-1] = y[k]
8786
end
88-
end
87+
end
8988
bnum = div(bnum,2)
9089
end
9190

0 commit comments

Comments
 (0)