Skip to content

Commit 4c95e98

Browse files
Merge branch 'master' into implement-stacks-queues-rust
2 parents 962e854 + 0aa5333 commit 4c95e98

File tree

41 files changed

+292
-125
lines changed

Some content is hidden

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

41 files changed

+292
-125
lines changed

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Ubuntu",
55
"build": {
6-
"dockerfile": "Dockerfile",
6+
"dockerfile": "../Dockerfile",
77
// Update 'VARIANT' to pick an Ubuntu version: focal, bionic
88
"args": { "VARIANT": "focal" }
99
},
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Publish Docker
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@master
11+
- name: Publish to Registry
12+
uses: elgohr/Publish-Docker-Github-Action@master
13+
with:
14+
name: algorithm-archivists/aaa-langs
15+
username: ${{ github.actor }}
16+
password: ${{ secrets.GITHUB_TOKEN }}
17+
registry: ghcr.io

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,7 @@ vscode/
524524

525525
# SCons build directory
526526
build/
527+
528+
# Cargo artifacts
529+
Cargo.lock
530+
target/

.nojekyll

Whitespace-only changes.

.devcontainer/Dockerfile renamed to Dockerfile

Lines changed: 13 additions & 9 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 libfftw3-dev
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 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
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
@@ -40,17 +40,16 @@ ENV PATH=$PATH:~/dlang/dmd-$DLANG_VERSION/linux/bin64/
4040
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'
4141
ENV PATH=$PATH:/usr/local/go/bin
4242

43-
# Setup Kotlin (doesnt unzip right maybe?)
44-
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'
45-
RUN unzip /usr/local/kotlinc.zip
46-
ENV PATH=$PATH:/usr/local/kotlinc/bin
43+
# Setup Kotlin
44+
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
45+
ENV PATH=$PATH:~/kotlin/kotlinc/bin
4746

4847
# Setup lolcode
49-
## Use: https://github.com/justinmeza/lci
48+
RUN git clone https://github.com/justinmeza/lci.git ~/lolcode && cd ~/lolcode && mkdir build && cd build && cmake .. && make -B
49+
ENV PATH=$PATH:~/lolcode/build
5050

5151
# Setup Piet
52-
## Use: https://github.com/boothby/repiet
53-
52+
RUN pip install repiet
5453

5554
# Setup Matlab
5655
# ?????? This is a licensed language???
@@ -73,6 +72,9 @@ RUN sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu fo
7372
RUN sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D9D33FCD84D82C17288BA03B3C9A6980F827E01E
7473
RUN sudo add-apt-repository 'deb http://ppa.launchpad.net/plt/racket/ubuntu focal main'
7574

75+
# Setup Rust
76+
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
77+
7678
# Setup Scratch
7779
## using 1.x right now.... in future checkout snap or adobe air?
7880

@@ -86,7 +88,8 @@ ENV PATH=$PATH:~/swift/usr/bin
8688
RUN export DEBIAN_FRONTEND=noninteractive && apt-get -y install --no-install-recommends vim
8789

8890
# Setup whitespace
89-
## ?
91+
RUN mkdir -p ~/whitespace && git clone https://github.com/wspace/whitespace-haskell ~/whitespace && cd ~/whitespace && make -B
92+
ENV PATH=$PATH:~/whitespace
9093

9194
# Setup Elm
9295
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 && \
@@ -102,6 +105,7 @@ ENV PATH=$PATH:~/vlang/v
102105
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
103106
&& apt-get -y install --no-install-recommends crystal dart nim powershell scala dotnet-sdk-5.0 r-base racket
104107

108+
105109
RUN pip install wheel matplotlib numpy coconut scons
106110

107111
RUN sudo sh -c 'npm install -g typescript'

SConscript

Lines changed: 0 additions & 10 deletions
This file was deleted.

SConstruct

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,66 @@ This provides Builder objects for each of the language implementations in the AA
55
66
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.
77
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."""
8+
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."""
99

1010
from pathlib import Path
11+
import os
1112

12-
env = Environment()
13+
rust_cargo_builder = Builder(action=['cargo build --bins --manifest-path $MANIFEST',
14+
Move('$TARGET$PROGSUFFIX', '$SOURCE_DIR/target/debug/main$PROGSUFFIX')])
15+
16+
rust_rustc_builder = Builder(action='rustc $SOURCE -o $TARGET$PROGSUFFIX')
17+
18+
go_builder = Builder(action='go build -o $TARGET$PROGSUFFIX $SOURCE')
19+
20+
env = Environment(ENV=os.environ,
21+
BUILDERS={'rustc': rust_rustc_builder,
22+
'cargo': rust_cargo_builder,
23+
'Go': go_builder},
24+
tools=['gcc', 'gnulink', 'g++', 'gas', 'gfortran'])
25+
26+
env['CCFLAGS'] = ''
27+
env['CXXFLAGS'] = '-std=c++17'
28+
env['ASFLAGS'] = '--64'
1329

1430
# Add other languages here when you want to add language targets
15-
languages = ['c']
31+
# Put 'name_of_language_directory' : 'file_extension'
32+
languages = {
33+
'c': 'c',
34+
'cpp': 'cpp',
35+
'asm-x64': 's',
36+
'rust': 'rs',
37+
'go': 'go',
38+
'fortran': 'f90',
39+
}
1640

1741
env.C = env.Program
42+
env.CPlusPlus = env.Program
43+
env.X64 = env.Program
44+
env.Fortran = env.Program
45+
46+
Export('env')
47+
48+
sconscripts = []
49+
files_to_compile = {language: [] for language in languages}
50+
51+
for chapter_dir in Path.cwd().joinpath('contents').iterdir():
52+
if (code_dir := (chapter_dir / 'code')).exists():
53+
for path in code_dir.iterdir():
54+
if path.stem in languages:
55+
# Check for overriding sconscript
56+
if (sconscript_path := path / 'SConscript').exists():
57+
sconscripts.append(sconscript_path)
58+
SConscript(sconscript_path, exports='env')
59+
else:
60+
files_to_compile[path.stem].extend(path.glob(f'*.{languages[path.stem]}'))
1861

19-
SConscript('SConscript', exports='env languages')
62+
sconscript_dir_path = Path('sconscripts')
63+
for language, files in files_to_compile.items():
64+
if files:
65+
if (sconscript_path := sconscript_dir_path / f"{language}_SConscript").exists():
66+
SConscript(sconscript_path, exports = {'files_to_compile': files,
67+
'language': language})
68+
else:
69+
print(f'{language} file found at {files[0]}, but no sconscript file is present ')
2070

contents/approximate_counting/code/c/approximate_counting.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,24 @@ void test_approximation_count(size_t n_trials, size_t n_items, double a,
6363
}
6464
double avg = sum / n_trials;
6565

66-
assert(fabs((avg - n_items) / n_items) < threshold);
66+
if (fabs((avg - n_items) / n_items) < threshold){
67+
printf("passed\n");
68+
}
69+
else{
70+
printf("failed\n");
71+
}
6772
}
6873

6974
int main()
7075
{
7176
srand(time(NULL));
7277

73-
printf("Counting Tests, 100 trials\n");
74-
printf("testing 1000, a = 30, 10%% error\n");
78+
printf("[#]\nCounting Tests, 100 trials\n");
79+
printf("[#]\ntesting 1,000, a = 30, 10%% error\n");
7580
test_approximation_count(100, 1000, 30, 0.1);
76-
printf("testing 12345, a = 10, 10%% error\n");
81+
printf("[#]\ntesting 12,345, a = 10, 10%% error\n");
7782
test_approximation_count(100, 12345, 10, 0.1);
78-
printf("testing 222222, a = 0.5, 20%% error\n");
83+
printf("[#]\ntesting 222,222, a = 0.5, 20%% error\n");
7984
test_approximation_count(100, 222222, 0.5, 0.2);
8085

8186
return 0;

contents/approximate_counting/code/cpp/approximate_counting.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ auto test_approximate_count(
5555
for (auto i = 0; i < n_trials; ++i)
5656
sum += approximate_count(n_items, a);
5757
const auto avg = sum / n_trials;
58-
return std::abs((avg - n_items) / n_items) < threshold ? "pass" : "fail";
58+
return std::abs((avg - n_items) / n_items) < threshold ? "passed" : "failed";
5959
}
6060

6161
int main() {
62-
std::cout << "Counting Tests, 100 trials\n";
62+
std::cout << "[#]\nCounting Tests, 100 trials\n";
6363

64-
std::cout << "testing 1,000, a = 30, 10% error "
64+
std::cout << "[#]\ntesting 1,000, a = 30, 10% error \n"
6565
<< test_approximate_count(100, 1000, 30, 0.1) << "\n";
66-
std::cout << "testing 12,345, a = 10, 10% error "
66+
std::cout << "[#]\ntesting 12,345, a = 10, 10% error \n"
6767
<< test_approximate_count(100, 12345, 10, 0.1) << "\n";
6868
// Note : with a lower a, we need more trials, so a higher % error here.
69-
std::cout << "testing 222,222, a = 0.5, 20% error "
69+
std::cout << "[#]\ntesting 222,222, a = 0.5, 20% error \n"
7070
<< test_approximate_count(100, 222222, 0.5, 0.2) << "\n";
7171
}

contents/approximate_counting/code/julia/approximate_counting.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,21 @@ function test_approximate_count(n_trials, n_items, a, threshold)
4747

4848
avg = sum(samples)/n_trials
4949

50-
@test (abs((avg - n_items) / n_items) < threshold)
50+
if (abs((avg - n_items) / n_items) < threshold)
51+
println("passed")
52+
else
53+
println("failed")
54+
end
5155
end
5256

53-
@testset "Counting Tests, 100 trials" begin
54-
println("testing 1,000, a = 30, 10% error")
55-
test_approximate_count(100, 1000, 30, 0.1)
56-
println("testing 12,345, a = 10, 10% error")
57-
test_approximate_count(100, 12345, 10, 0.1)
58-
# Note: with a lower a, we need more trials, so a higher % error here.
59-
println("testing 222,222, a = 0.5, 20% error")
60-
test_approximate_count(100, 222222, 0.5, 0.2)
61-
end
57+
println("[#]\nCounting Tests, 100 trials")
58+
59+
println("[#]\ntesting 1,000, a = 30, 10% error")
60+
test_approximate_count(100, 1000, 30, 0.1)
61+
62+
println("[#]\ntesting 12,345, a = 10, 10% error")
63+
test_approximate_count(100, 12345, 10, 0.1)
64+
65+
# Note: with a lower a, we need more trials, so a higher % error here.
66+
println("[#]\ntesting 222,222, a = 0.5, 20% error")
67+
test_approximate_count(100, 222222, 0.5, 0.2)

0 commit comments

Comments
 (0)