Skip to content

Commit e651b64

Browse files
authored
Merge branch 'master' into devcontainer-vlang
2 parents 91410d7 + 4a81890 commit e651b64

File tree

45 files changed

+612
-423
lines changed

Some content is hidden

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

45 files changed

+612
-423
lines changed

.devcontainer/Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
66

77
# [Optional] Uncomment this section to install additional OS packages.
88
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
9-
&& 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
9+
&& 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
1010

1111
# Setup Crystal
1212
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
@@ -99,6 +99,7 @@ ENV PATH=$PATH:~/vlang/v
9999
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
100100
&& apt-get -y install --no-install-recommends crystal dart nim powershell scala dotnet-sdk-5.0 r-base racket
101101

102-
RUN pip install wheel matplotlib numpy coconut
102+
RUN pip install wheel matplotlib numpy coconut scons
103103

104104
RUN sudo sh -c 'npm install -g typescript'
105+

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,10 @@ vscode/
517517

518518
# aspell
519519
*.bak
520+
521+
# SCons intermidiate files
522+
.sconsign.dblite
523+
*.o
524+
525+
# SCons build directory
526+
build/

CONTRIBUTORS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ This file lists everyone, who contributed to this repo and wanted to show up her
5151
- Vincent Zalzal
5252
- Jonathan D B Van Schenck
5353
- James Goytia
54-
- Amaras
54+
- Sammy Plat
5555
- Jonathan Dönszelmann
5656
- Ishaan Verma
5757
- Delphi1024

SConscript

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pathlib import Path
2+
3+
Import('*')
4+
5+
for p in Path('contents').iterdir():
6+
if (q := (p / 'code')).exists():
7+
for path in q.iterdir():
8+
if path.stem in languages:
9+
env.SConscript(path / 'SConscript', exports='env',
10+
must_exist=0)

SConstruct

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
SCons top-level build description (SConstruct) for the Arcane Algorithm Achive
3+
4+
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.
5+
6+
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.
7+
8+
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."""
9+
10+
from pathlib import Path
11+
12+
env = Environment()
13+
14+
# Add other languages here when you want to add language targets
15+
languages = ['c']
16+
17+
env.C = env.Program
18+
19+
SConscript('SConscript', exports='env languages')
20+

contents/IFS/code/c/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS='m')

contents/barnsley/code/c/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))

contents/computus/code/c/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS=['m', 'fftw3'])

contents/cooley_tukey/cooley_tukey.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ For some reason, though, putting code to this transformation really helped me fi
8181
[import:7-13, lang:"haskell"](code/haskell/fft.hs)
8282
{% sample lang="py" %}
8383
[import:6-12, lang:"python"](code/python/fft.py)
84-
{% sample lang="scratch" %}
85-
[import:4-13, lang:"julia"](code/julia/fft.jl)
8684
{% sample lang="asm-x64" %}
8785
[import:15-74, lang:"asm-x64"](code/asm-x64/fft.s)
8886
{% sample lang="js" %}
@@ -136,8 +134,6 @@ In the end, the code looks like:
136134
[import:15-28, lang:"haskell"](code/haskell/fft.hs)
137135
{% sample lang="py" %}
138136
[import:15-26, lang:"python"](code/python/fft.py)
139-
{% sample lang="scratch" %}
140-
[import:16-32, lang:"julia"](code/julia/fft.jl)
141137
{% sample lang="asm-x64" %}
142138
[import:76-165, lang:"asm-x64"](code/asm-x64/fft.s)
143139
{% sample lang="js" %}
@@ -251,8 +247,6 @@ Note: I implemented this in Julia because the code seems more straightforward in
251247
[import, lang:"haskell"](code/haskell/fft.hs)
252248
{% sample lang="py" %}
253249
[import, lang:"python"](code/python/fft.py)
254-
{% sample lang="scratch" %}
255-
Some rather impressive scratch code was submitted by Jie and can be found here: https://scratch.mit.edu/projects/37759604/#editor
256250
{% sample lang="asm-x64" %}
257251
[import, lang:"asm-x64"](code/asm-x64/fft.s)
258252
{% sample lang="js" %}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))

contents/flood_fill/code/c/SConscript

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS='m')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS='m')
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'), LIBS=['m', 'fftw3'])
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))

contents/tree_traversal/code/c++/tree_example.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct node {
1717
// Simple recursive scheme for DFS
1818
void dfs_recursive(node const& n) {
1919
// Here we are doing something...
20-
std::cout << n.value << '\n';
20+
std::cout << n.value << ' ';
2121
for (auto const& child : n.children) {
2222
dfs_recursive(child);
2323
}
@@ -27,23 +27,23 @@ void dfs_recursive_postorder(node const& n) {
2727
for (auto const& child : n.children) {
2828
dfs_recursive_postorder(child);
2929
}
30-
std::cout << n.value << '\n';
30+
std::cout << n.value << ' ';
3131
}
3232

3333

3434
void dfs_recursive_inorder_btree(node const& n) {
3535
switch (n.children.size()) {
3636
case 2:
3737
dfs_recursive_inorder_btree(n.children[0]);
38-
std::cout << n.value << '\n';
38+
std::cout << n.value << ' ';
3939
dfs_recursive_inorder_btree(n.children[1]);
4040
break;
4141
case 1:
4242
dfs_recursive_inorder_btree(n.children[0]);
43-
std::cout << n.value << '\n';
43+
std::cout << n.value << ' ';
4444
break;
4545
case 0:
46-
std::cout << n.value << '\n';
46+
std::cout << n.value << ' ';
4747
break;
4848
default:
4949
std::cout << "This is not a binary tree.\n";
@@ -61,7 +61,7 @@ void dfs_stack(node const& n) {
6161
while (stack.size() > 0) {
6262
auto const& temp = *stack.top();
6363
stack.pop();
64-
std::cout << temp.value << '\n';
64+
std::cout << temp.value << ' ';
6565

6666
for (auto const& child : temp.children) {
6767
stack.push(&child);
@@ -78,7 +78,7 @@ void bfs_queue(node const& n) {
7878
auto const& temp = *queue.front();
7979
queue.pop();
8080

81-
std::cout << temp.value << '\n';
81+
std::cout << temp.value << ' ';
8282
for (auto const& child : temp.children) {
8383
queue.push(&child);
8484
}
@@ -100,18 +100,23 @@ node create_tree(size_t num_row, size_t num_child) {
100100

101101
int main() {
102102
// Creating Tree in main
103-
auto root = create_tree(3, 3);
103+
auto root = create_tree(2, 3);
104104
auto binary_root = create_tree(3, 2);
105-
std::cout << "DFS recursive:\n";
105+
std::cout << "[#]\nRecursive DFS:\n";
106106
dfs_recursive(root);
107-
std::cout << "DFS post order recursive:\n";
107+
std::cout << '\n';
108+
std::cout << "[#]\nRecursive Postorder DFS:\n";
108109
dfs_recursive_postorder(root);
109-
std::cout << "DFS inorder binary tree:\n";
110-
dfs_recursive_inorder_btree(binary_root);
111-
std::cout << "DFS stack:\n";
110+
std::cout << '\n';
111+
std::cout << "[#]\nStack-based DFS:\n";
112112
dfs_stack(root);
113-
std::cout << "BFS queue:\n";
113+
std::cout << '\n';
114+
std::cout << "[#]\nQueue-based BFS:\n";
114115
bfs_queue(root);
116+
std::cout << '\n';
117+
std::cout << "[#]\nRecursive Inorder DFS for Binary Tree:\n";
118+
dfs_recursive_inorder_btree(binary_root);
119+
std::cout << '\n';
115120

116121
return 0;
117122
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Import('*')
2+
from pathlib import Path
3+
4+
dirname = Path.cwd().parents[1].stem
5+
6+
env.C(f'#/build/c/{dirname}', Glob('*.c'))

contents/tree_traversal/code/c/tree_traversal.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void destroy_tree(struct node n) {
3535
}
3636

3737
void dfs_recursive(struct node n) {
38-
printf("%d\n", n.id);
38+
printf("%d ", n.id);
3939

4040
if (n.children) {
4141
for (size_t i = 0; i < n.children_size; ++i) {
@@ -49,22 +49,22 @@ void dfs_recursive_postorder(struct node n) {
4949
dfs_recursive_postorder(n.children[i]);
5050
}
5151

52-
printf("%d\n", n.id);
52+
printf("%d ", n.id);
5353
}
5454

5555
void dfs_recursive_inorder_btree(struct node n) {
5656
switch (n.children_size) {
5757
case 2:
5858
dfs_recursive_inorder_btree(n.children[0]);
59-
printf("%d\n", n.id);
59+
printf("%d ", n.id);
6060
dfs_recursive_inorder_btree(n.children[1]);
6161
break;
6262
case 1:
6363
dfs_recursive_inorder_btree(n.children[0]);
64-
printf("%d\n", n.id);
64+
printf("%d ", n.id);
6565
break;
6666
case 0:
67-
printf("%d\n", n.id);
67+
printf("%d ", n.id);
6868
break;
6969
default:
7070
printf("This is not a binary tree.\n");
@@ -83,7 +83,7 @@ void dfs_stack(struct node n) {
8383
break;
8484
}
8585

86-
printf("%d\n", tmp->id);
86+
printf("%d ", tmp->id);
8787
for (size_t i = 0; i < tmp->children_size; ++i) {
8888
stack_push(&stk, &tmp->children[i]);
8989
}
@@ -103,7 +103,7 @@ void bfs_queue(struct node n) {
103103
break;
104104
}
105105

106-
printf("%d\n", tmp->id);
106+
printf("%d ", tmp->id);
107107
for (size_t i = 0; i < tmp->children_size; ++i) {
108108
enqueue(&q, &tmp->children[i]);
109109
}
@@ -113,9 +113,31 @@ void bfs_queue(struct node n) {
113113
}
114114

115115
int main() {
116-
struct node root = create_tree(3, 3);
116+
struct node root = create_tree(2, 3);
117+
118+
printf("[#]\nRecursive DFS:\n");
119+
dfs_recursive(root);
120+
printf("\n");
121+
122+
printf("[#]\nRecursive Postorder DFS:\n");
123+
dfs_recursive_postorder(root);
124+
printf("\n");
125+
126+
printf("[#]\nStack-based DFS:\n");
127+
dfs_stack(root);
128+
printf("\n");
129+
130+
printf("[#]\nQueue-based BFS:\n");
117131
bfs_queue(root);
132+
printf("\n");
133+
118134
destroy_tree(root);
135+
struct node root_binary = create_tree(3, 2);
119136

137+
printf("[#]\nRecursive Inorder DFS for Binary Tree:\n");
138+
dfs_recursive_inorder_btree(root_binary);
139+
printf("\n");
140+
141+
destroy_tree(root_binary);
120142
return 0;
121143
}

0 commit comments

Comments
 (0)