Skip to content

Commit bfc018f

Browse files
authored
Merge branch 'master' into tree-traversal-csharp-error
2 parents a545dbd + 2000ab3 commit bfc018f

File tree

31 files changed

+779
-424
lines changed

31 files changed

+779
-424
lines changed

.devcontainer/Dockerfile

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ RUN sudo sh -c 'sudo dpkg -i packages-microsoft-prod.deb'
3131
RUN sudo sh -c 'rm packages-microsoft-prod.deb'
3232

3333
# Setup D Lang
34-
RUN sudo sh -c 'mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh'
35-
RUN sudo sh -c 'bash ~/dlang/install.sh'
36-
## From Docs not needed though
37-
# RUN sudo sh -c 'source ~/dlang/dmd-2.097.2/activate'
38-
ENV PATH=$PATH:/root/dlang/dmd-2.097.2/linux/bin64
34+
ENV DLANG_VERSION=2.097.2
35+
RUN mkdir -p ~/dlang && wget https://dlang.org/install.sh -O ~/dlang/install.sh
36+
RUN bash ~/dlang/install.sh dmd-$DLANG_VERSION
37+
ENV PATH=$PATH:~/dlang/dmd-$DLANG_VERSION/linux/bin64/
3938

4039
# Setup Go
4140
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'
@@ -56,17 +55,14 @@ ENV PATH=$PATH:/usr/local/kotlinc/bin
5655
# Setup Matlab
5756
# ?????? This is a licensed language???
5857

59-
# Setup Emojicode (in progress)
60-
RUN sudo sh -c 'wget -c https://github.com/emojicode/emojicode/releases/download/v1.0-beta.2/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz -O /usr/local/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz'
61-
RUN sudo tar -xvzf /usr/local/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz
62-
# && cd ~/emojicode/ && echo && ./install.sh'
63-
ENV PATH=$PATH:/usr/local/Emojicode-1.0-beta.2-Linux-x86_64
64-
65-
# Setup Factor (in progress)
66-
RUN mkdir -p ~/factor && wget https://downloads.factorcode.org/releases/0.98/factor-linux-x86-64-0.98.tar.gz -O ~/factor/factor.tar.gz
67-
RUN tar -xzf /root/factor/factor.tar.gz
68-
# && rm ~/factor/factor.tar.gz
69-
ENV PATH=$PATH:/root/factor/factor
58+
# Setup Emojicode
59+
RUN mkdir -p ~/emojicode && wget -c https://github.com/emojicode/emojicode/releases/download/v1.0-beta.2/Emojicode-1.0-beta.2-Linux-x86_64.tar.gz -O ~/emojicode/emojicode.tar.gz && \
60+
tar -xzf ~/emojicode/emojicode.tar.gz -C ~/emojicode --strip-components=1
61+
ENV PATH=$PATH:~/emojicode
62+
63+
# Setup Factor
64+
RUN mkdir -p ~/factor && wget https://downloads.factorcode.org/releases/0.98/factor-linux-x86-64-0.98.tar.gz -O ~/factor/factor.tar.gz && tar -xzf ~/factor/factor.tar.gz -C ~/factor --strip-components=1
65+
ENV PATH=$PATH:~/factor/factor
7066

7167
# Setup R
7268
RUN sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,4 @@ This file lists everyone, who contributed to this repo and wanted to show up her
6060
- Ridham177
6161
- Hugo Salou
6262
- Dimitri Belopopsky
63+
+ Henrik Abel Christensen

contents/approximate_counting/code/c++/approximate_counting.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ auto test_approximate_count(
6161
int main() {
6262
std::cout << "Counting Tests, 100 trials\n";
6363

64-
std::cout << "testing 1,000, a = 30, 1% error "
64+
std::cout << "testing 1,000, a = 30, 10% error "
6565
<< test_approximate_count(100, 1000, 30, 0.1) << "\n";
66-
std::cout << "testing 12,345, a = 10, 1% error "
66+
std::cout << "testing 12,345, a = 10, 10% error "
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, 10% error "
69+
std::cout << "testing 222,222, a = 0.5, 20% error "
7070
<< test_approximate_count(100, 222222, 0.5, 0.2) << "\n";
7171
}

contents/approximate_counting/code/c/approximate_counting.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ int main()
7171
srand(time(NULL));
7272

7373
printf("Counting Tests, 100 trials\n");
74-
printf("testing 1000, a = 30, 1%% error\n");
74+
printf("testing 1000, a = 30, 10%% error\n");
7575
test_approximation_count(100, 1000, 30, 0.1);
76-
printf("testing 12345, a = 10, 1%% error\n");
76+
printf("testing 12345, a = 10, 10%% error\n");
7777
test_approximation_count(100, 12345, 10, 0.1);
78-
printf("testing 222222, a = 0.5, 10%% error\n");
78+
printf("testing 222222, a = 0.5, 20%% error\n");
7979
test_approximation_count(100, 222222, 0.5, 0.2);
8080

8181
return 0;

contents/approximate_counting/code/julia/approximate_counting.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ function test_approximate_count(n_trials, n_items, a, threshold)
5151
end
5252

5353
@testset "Counting Tests, 100 trials" begin
54-
println("testing 1,000, a = 30, 1% error")
54+
println("testing 1,000, a = 30, 10% error")
5555
test_approximate_count(100, 1000, 30, 0.1)
56-
println("testing 12,345, a = 10, 1% error")
56+
println("testing 12,345, a = 10, 10% error")
5757
test_approximate_count(100, 12345, 10, 0.1)
5858
# Note: with a lower a, we need more trials, so a higher % error here.
59-
println("testing 222,222, a = 0.5, 10% error")
59+
println("testing 222,222, a = 0.5, 20% error")
6060
test_approximate_count(100, 222222, 0.5, 0.2)
6161
end

contents/approximate_counting/code/python/approximate_counting.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def test_approximate_count(n_trials, n_items, a, threshold):
4141
if abs((avg - n_items)/n_items) < threshold:
4242
print("passed")
4343

44-
print("testing 1,000, a = 30, 1% error")
44+
print("testing 1,000, a = 30, 10% error")
4545
test_approximate_count(100, 1000, 30, 0.1)
46-
print("testing 12,345, a = 10, 1% error")
46+
print("testing 12,345, a = 10, 10% error")
4747
test_approximate_count(100, 12345, 10, 0.1)
48-
print("testing 222,222, a = 0.5, 10% error")
48+
print("testing 222,222, a = 0.5, 20% error")
4949
test_approximate_count(100, 222222, 0.5, 0.2)

contents/huffman_encoding/code/julia/huffman.jl

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using Test
2+
13
# This is for the PriorityQueue
24
using DataStructures
35

@@ -13,8 +15,6 @@ struct Branch
1315
end
1416

1517
const Node = Union{Leaf, Branch}
16-
isbranch(branch::Branch) = true
17-
isbranch(other::T) where {T} = false
1818

1919
function codebook_recurse!(leaf::Leaf, code::String,
2020
dict::Dict{Char,String})
@@ -33,7 +33,11 @@ end
3333
# This outputs encoding Dict to be used for encoding
3434
function create_codebook(n::Node)
3535
codebook = Dict{Char,String}()
36-
codebook_recurse!(n, "", codebook)
36+
if isa(n, Leaf)
37+
codebook[n.key]="0"
38+
else
39+
codebook_recurse!(n, "", codebook)
40+
end
3741
return codebook
3842
end
3943

@@ -85,14 +89,19 @@ function decode(huffman_tree::Node, bitstring::String)
8589
current = huffman_tree
8690
final_string = ""
8791
for i in bitstring
88-
if (i == '1')
89-
current = current.left
92+
if isa(huffman_tree, Branch)
93+
if (i == '1')
94+
current = current.left
95+
else
96+
current = current.right
97+
end
98+
99+
if (!isa(current, Branch))
100+
final_string *= string(current.key)
101+
current = huffman_tree
102+
end
90103
else
91-
current = current.right
92-
end
93-
if (!isbranch(current))
94-
final_string = final_string * string(current.key)
95-
current = huffman_tree
104+
final_string *= string(huffman_tree.key)
96105
end
97106
end
98107

@@ -102,11 +111,13 @@ end
102111
function two_pass_huffman(phrase::String)
103112
huffman_tree = create_tree(phrase)
104113
codebook = create_codebook(huffman_tree)
105-
println(codebook)
106114
bitstring = encode(codebook, phrase)
107115
final_string = decode(huffman_tree, bitstring)
108-
println(bitstring)
109-
println(final_string)
116+
return final_string
110117
end
111118

112-
two_pass_huffman("bibbity bobbity")
119+
@testset "b-string tests" begin
120+
@test two_pass_huffman("b") == "b"
121+
@test two_pass_huffman("bbbbbbbb") == "bbbbbbbb"
122+
@test two_pass_huffman("bibbity bobbity") == "bibbity bobbity"
123+
end
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import java.util.List;
2+
import java.util.ArrayList;
3+
4+
public class QueueTest {
5+
6+
public static void main(String[] args) {
7+
IQueue<Integer> intQueue = new Queue<>();
8+
9+
intQueue.enqueue(4);
10+
intQueue.enqueue(5);
11+
intQueue.enqueue(9);
12+
13+
System.out.println(intQueue.dequeue());
14+
System.out.println(intQueue.size());
15+
System.out.println(intQueue.front());
16+
}
17+
18+
}
19+
20+
21+
interface IQueue<T> {
22+
23+
/*
24+
* 'dequeue' removes the first element from the queue and returns it
25+
*/
26+
T dequeue();
27+
28+
/*
29+
* 'enqueue' adds an element at the end of the queue and returns the new size
30+
*/
31+
int enqueue(T element);
32+
33+
34+
/*
35+
* 'size' returns the size of the queue
36+
*/
37+
int size();
38+
39+
/*
40+
* 'front' returns the first element of the queue without removing it
41+
*/
42+
T front();
43+
}
44+
45+
46+
public class Queue<T> implements IQueue<T> {
47+
48+
private List<T> list;
49+
50+
public Queue() {
51+
this.list = new ArrayList<>();
52+
}
53+
54+
public T dequeue() {
55+
return this.list.remove(0);
56+
}
57+
58+
public int enqueue(T element) {
59+
this.list.add(element);
60+
return this.size();
61+
}
62+
63+
public int size() {
64+
return this.list.size();
65+
}
66+
67+
public T front() {
68+
return this.list.get(0);
69+
}
70+
71+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import java.util.List;
2+
import java.util.ArrayList;
3+
4+
5+
public class StackTest {
6+
7+
public static void main(String[] args) {
8+
IStack<Integer> intStack = new Stack<>();
9+
10+
intStack.push(4);
11+
intStack.push(5);
12+
intStack.push(9);
13+
14+
System.out.println(intStack.pop());
15+
System.out.println(intStack.size());
16+
System.out.println(intStack.top());
17+
}
18+
19+
}
20+
21+
22+
interface IStack<T> {
23+
/*
24+
* 'pop' removed the last element from the stack and returns it
25+
*/
26+
T pop();
27+
28+
/*
29+
* 'push' adds an element to at the end of the stack and returns the new size
30+
*/
31+
int push(T element);
32+
33+
/*
34+
* 'size' returns the length of the stack
35+
*/
36+
int size();
37+
38+
/*
39+
* 'top' returns the first element of the stack
40+
*/
41+
T top();
42+
}
43+
44+
45+
public class Stack<T> implements IStack<T> {
46+
47+
private List<T> list;
48+
49+
public Stack() {
50+
this.list = new ArrayList<>();
51+
}
52+
53+
public T pop() {
54+
return this.list.remove(this.size() - 1);
55+
}
56+
57+
public int push(T element) {
58+
this.list.add(element);
59+
return this.size();
60+
}
61+
62+
public int size() {
63+
return this.list.size();
64+
}
65+
66+
public T top() {
67+
return this.list.get(this.size() - 1);
68+
}
69+
70+
}
71+
72+

contents/stacks_and_queues/stacks_and_queues.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ Here is a simple implementation of a stack:
1818
{% method %}
1919
{% sample lang="ts" %}
2020
[import, lang:"typescript"](code/typescript/stack.ts)
21+
{% sample lang="java" %}
22+
[import, lang:"java"](code/java/Stack.java)
2123
{% endmethod %}
2224

2325
Here is a simple implementation of a queue:
2426
{% method %}
2527
{% sample lang="ts" %}
2628
[import, lang:"typescript"](code/typescript/queue.ts)
29+
{% sample lang="java" %}
30+
[import, lang:"java" ](code/java/Queue.java)
2731
{% endmethod %}
2832

2933

0 commit comments

Comments
 (0)