├── .gitignore
├── README.md
├── algorithms
├── math
│ ├── factorial
│ │ ├── factorial.c
│ │ ├── factorial.cpp
│ │ ├── factorial.hs
│ │ ├── factorial.php
│ │ ├── factorial.rs
│ │ └── factorial.ts
│ ├── fibonacci
│ │ ├── bottom-up.fibonacci.cpp
│ │ ├── fibonacci.cpp
│ │ └── recursive.fibonacci.cpp
│ ├── shoelace
│ │ └── shoelace.hs
│ └── sieve-of-eratosthenes
│ │ └── sieve-of-eratosthenes.ts
├── search
│ └── binary-search
│ │ ├── binary-search.c
│ │ ├── binary-search.cpp
│ │ ├── binary-search.php
│ │ ├── binary-search.rs
│ │ └── binary-search.ts
├── shuffling
│ └── fisher-yates-shuffle
│ │ ├── fisher-yates-shuffle.c
│ │ ├── fisher-yates-shuffle.cpp
│ │ ├── fisher-yates-shuffle.php
│ │ └── fisher-yates-shuffle.ts
└── sorting
│ ├── bubble-sort
│ ├── bubble-sort.c
│ ├── bubble-sort.cpp
│ ├── bubble-sort.hs
│ ├── bubble-sort.php
│ ├── bubble-sort.ts
│ └── recursive.bubble-sort.cpp
│ ├── gnome-sort
│ ├── gnome-sort.c
│ ├── gnome-sort.cpp
│ └── gnome-sort.ts
│ ├── insertion-sort
│ ├── insertion-sort.c
│ ├── insertion-sort.cpp
│ ├── insertion-sort.hs
│ ├── insertion-sort.php
│ └── insertion-sort.ts
│ ├── odd-even-sort
│ ├── odd-even-sort.c
│ ├── odd-even-sort.cpp
│ ├── odd-even-sort.php
│ └── odd-even-sort.ts
│ ├── quicksort
│ └── quicksort.ts
│ └── shell-sort
│ ├── shell-sort.c
│ ├── shell-sort.cpp
│ └── shell-sort.ts
├── banner.png
└── data-structures
├── stack
└── stack.ts
└── undirected-graph
└── undirected-graph.ts
/.gitignore:
--------------------------------------------------------------------------------
1 | *.js
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ### What's this project for?
4 | a hobby project to try out implementing some common algorithms and datastructres with different languages such as TS, C and Haskell.
5 |
--------------------------------------------------------------------------------
/algorithms/math/factorial/factorial.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | unsigned long long factorial(int num);
5 |
6 | int main() {
7 | unsigned long long answer = factorial(10);
8 | printf("%llu\n", answer);
9 | return 0;
10 | }
11 |
12 | unsigned long long factorial(int num) {
13 | unsigned long long tmp = 1;
14 | for (int l = 1; l <= num; l++)
15 | tmp = tmp * l;
16 | return tmp;
17 | }
--------------------------------------------------------------------------------
/algorithms/math/factorial/factorial.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | unsigned long long
4 | factorial(unsigned long long num)
5 | {
6 | if (num == 1)
7 | return num;
8 | return factorial(num - 1) * num;
9 | }
10 |
11 | int
12 | main()
13 | {
14 | unsigned long long num = 50;
15 | unsigned long long answer = factorial(num);
16 | printf("%llu\n", answer);
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/algorithms/math/factorial/factorial.hs:
--------------------------------------------------------------------------------
1 | factorial :: (Integral n) => n -> n
2 | factorial n = product [1..n]
3 |
4 | main :: IO ()
5 | main = do
6 | putStr "factorial 10 = "
7 | print (factorial 10)
8 |
--------------------------------------------------------------------------------
/algorithms/math/factorial/factorial.php:
--------------------------------------------------------------------------------
1 | u64 {
2 | return if num == 1 { num } else { factorial(num-1) * num };
3 | }
4 |
5 | fn main() {
6 | let result = factorial(6);
7 | println!("6! = {}", result);
8 | }
--------------------------------------------------------------------------------
/algorithms/math/factorial/factorial.ts:
--------------------------------------------------------------------------------
1 | const factorial = (num) => (num === 1 ? num : num * factorial(num - 1));
2 |
3 | const answer = factorial(10);
4 | console.log(answer);
5 |
--------------------------------------------------------------------------------
/algorithms/math/fibonacci/bottom-up.fibonacci.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | using namespace std;
4 |
5 | #define ll long long
6 |
7 | vector vec;
8 |
9 | ll
10 | fib(int n)
11 | {
12 |
13 | if (n <= 2)
14 | return n;
15 |
16 | else {
17 | vec.clear();
18 | vec.push_back(1);
19 | vec.push_back(1);
20 |
21 | for (int i = 2; i < n; ++i)
22 | vec.push_back(vec.at(i - 2) + vec.at(i - 1));
23 |
24 | return vec.at(n - 1);
25 | }
26 | }
27 |
28 | int
29 | main()
30 | {
31 | int n = 80;
32 |
33 | cout << fib(n) << endl;
34 | }
--------------------------------------------------------------------------------
/algorithms/math/fibonacci/fibonacci.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include