Skip to content

Commit 3da99aa

Browse files
committed
Change structure
1 parent b3f1016 commit 3da99aa

20 files changed

+143
-172
lines changed

Contributing.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ I'm trying to make informative and entertaining questions about topics that I li
44

55
#### Structure
66

7-
- Questions must be under [here](questions), as topic-name.md format.
8-
- Answers must be under [here](answers), as topic-name.md format.
9-
- The name of the question and its answer **must** be same.
10-
- If you want to give some materials for question, you should put them under a directory which has the **same** name with your question. Then put that directory [here](questions/materials).
7+
- Exercises must be under [here](exercises), as topic-name.md format.
8+
- If you want to give some materials for exercises, you should put them under a directory which has the **same** name with your exercise. Then put that directory [here](exercises/materials).
119

1210
#### Questions
1311

@@ -16,7 +14,6 @@ I'm trying to make informative and entertaining questions about topics that I li
1614
3. Ask the question and show additional materials if available.
1715
4. Write example input and output.
1816
5. Give extra information, resources and links.
19-
6. Go to answer link.
2017

2118
#### Answers
2219

@@ -27,8 +24,7 @@ I'm trying to make informative and entertaining questions about topics that I li
2724

2825
#### Readme
2926

30-
- Append your question and answer link with same format.
27+
- Append your exercise link with same format.
3128

3229

33-
34-
> Instead of creating questions, you can contribute via publishing a different approach to a question or solution with different programming language. Feel free to use any programming language, but please be careful to the format. You can ask me anything [from here]([email protected]).
30+
> Instead of creating exercises, you can contribute via publishing a different approach to a question or solution with different programming language. Feel free to use any programming language, but please be careful to the format. You can ask me anything [from here]([email protected]).

answers/fibonacci-finder.md

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

answers/perlin-noise.md

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

answers/approximating-pi.md renamed to exercises/approximating-pi.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
### Question - Approximating Pi
2+
3+
The number π (pi) is a mathematical constant defined as the ratio of a circle's circumference to its diameter. This magical number appears in many formulas in all areas of mathematics and physics.
4+
5+
Interestingly, pi is an irrational number, there can be no “final" digit of pi, because it's an irrational number that never ends. It has infinite digits and it keeps ongoing, forever, without ever repeating. Which means that its value cannot be expressed exactly as a simple fraction.
6+
7+
Since computers can't work with infinite decimals, they need to approximate pi. There are countless number of numerical methods to calculate the value of pi.
8+
9+
Write a program which approximates the value of π
10+
111
### Answer - Approximating Pi
212

313
There are a couple different ways of estimating π. I will use **[Monte Carlo Method](http://mathworld.wolfram.com/MonteCarloMethod.html)** with C programming.
@@ -155,5 +165,3 @@ int main()
155165
```
156166

157167
[Here](https://editor.p5js.org/ChrisOrban/sketches/ByERjxMKG) is a great visual explanation of what we tried to do using Javascript. Also in [this video](https://thecodingtrain.com/CodingChallenges/095-approximating-pi.html) Processing (Java) used.
158-
159-
_Go to [question](https://github.com/enesdemirag/programming-exercises/blob/master/questions/approximating-pi.md)._

answers/caesar-cipher.md renamed to exercises/caesar-cipher.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
### Question - Caesar Cipher
2+
3+
**Caesar Cipher** is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the text is replaced by a letter some fixed number of positions down the alphabet.
4+
5+
_Alphabet : "abcdefghijklmnopqrstuvwxyz"_
6+
7+
Write encrypt and decrypt functions for Caesar Cipher Encryption.
8+
9+
Example:
10+
```
11+
input : "hello", 5
12+
output : "mjqqt"
13+
```
14+
15+
```
16+
input : "Oazsdmfgxmfuaze", 12
17+
output : "Congratulations"
18+
```
19+
20+
You can watch this _[Khan Academy Video](https://www.khanacademy.org/computing/computer-science/cryptography/crypt/v/caesar-cipher)_ and read this _[article](http://www.cs.trincoll.edu/~crypto/historical/caesar.html)_ for more information.
21+
122
### Answer - Caesar Cipher
223

324
We read every character one by one using for loop in Python. Instead of using alphabet string I used Python's two build-in functions for shifting. ```ord()``` function converts character to its _[ascii code](https://theasciicode.com.ar)_ and the ```chr()``` function works vice-versa. Firstly we get the ascii number of the character, then add that shift value.
@@ -67,5 +88,3 @@ def encrypt(text, shift):
6788
cipher = cipher + lower_case_alphabet[(lower_case_alphabet.index(char) - shift) % 26]
6889
return cipher
6990
```
70-
71-
_Go to [question](https://github.com/enesdemirag/programming-exercises/blob/master/questions/caesar-cipher.md)._

questions/fibonacci-finder.md renamed to exercises/fibonacci-finder.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,29 @@ output : 10
2424

2525
For more information check out _[this](http://mathworld.wolfram.com/FibonacciNumber.html)_ website and *[wikipedia](https://en.wikipedia.org/wiki/Fibonacci_number)* page.
2626

27-
_Go to [answer](https://github.com/enesdemirag/programming-exercises/blob/master/answers/fibonacci-finder.md)._
27+
### Answer - Fibonacci Finder
28+
29+
Here is a function which returns the index of the input number in fibonacci sequence. If input value is not a member of fibonacci sequence it gives -1.
30+
31+
```matlab
32+
function output = fibonacci_finder(input)
33+
% Fibonacci Finder: Program that determines a number if its Fibonacci is given.
34+
a = 0;
35+
b = 1;
36+
temp = 0;
37+
count = 0;
38+
while(true)
39+
temp = a;
40+
a = b;
41+
b = temp + b;
42+
if(a == input) % If
43+
break;
44+
end
45+
else if(a > input) % If input number didn't within the sequence
46+
count = -1; % Return -1
47+
break;
48+
end
49+
count = count + 1;
50+
end
51+
output = count; % Index in sequence
52+
end```

answers/image-kernels.md renamed to exercises/image-kernels.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,37 @@
1+
### Question - Image Kernels
2+
3+
An **image kernel** is a small matrix used to apply effects such as blurring, sharpening, and edge detection. They are like ancestors of modern image processing techniques and even used today in machine learning for _feature extraction_, a technique for determining the most important portions of an image.
4+
5+
Below matrix is a 3x3 Gaussian Blur Kernel. For each pixel in the image, we take 3x3 block of neighbor pixels and multiply each pixel by the corresponding entry of the kernel and then take the sum. That sum becomes a new value of the pixel.
6+
7+
<table align = center>
8+
<tr>
9+
<td align = center>0.0625</td>
10+
<td align = center>0.125</td>
11+
<td align = center>0.0625</td>
12+
</tr>
13+
<tr>
14+
<td align = center>0.125</td>
15+
<td align = center>0.25</td>
16+
<td align = center>0.125</td>
17+
</tr>
18+
<tr>
19+
<td align = center>0.0625</td>
20+
<td align = center>0.125</td>
21+
<td align = center>0.0625</td>
22+
</tr>
23+
</table>
24+
25+
Write a function that can apply the entered kernel to an image. You can use image *[here](materials/image-processing)*.
26+
27+
Example:
28+
```
29+
input : (image in a matrix form), [[0, -1, 0], [-1, 5, -1], [0, -1, 0]]
30+
output : (filtered image in a matrix form)
31+
```
32+
33+
If you want to learn more about image kernels, you can check *[wikipedia](https://bit.ly/2yfaapD)* page and _[this documentation](https://docs.gimp.org/en/gimp-filter-convolution-matrix.html)_ from gimp, also I certainly suggest you to look at _[this website](http://setosa.io/ev/image-kernels/)_ for visually explanation of image kernels.
34+
135
### Answer - Image Kernels
236

337
I will use Python for this solution. Before coding, we need to import _[numpy](https://docs.scipy.org/doc/numpy/user/whatisnumpy.html)_ and _[matplotlib](https://matplotlib.org/)_ modules to our program. Numpy enables us to perform fast operations on matrices. Of course we can write our program without using numpy but it would be much harder. Matplotlib actually a plotting library for python but we need it just for showing our filtered image.
@@ -41,5 +75,3 @@ def filter(image, kernel):
4175
plt.imshow(result, cmap="gray") # Show filtered image
4276
plt.show()
4377
```
44-
45-
_Go to [question](https://github.com/enesdemirag/programming-exercises/blob/master/questions/image-kernels.md)._

answers/inverse-factorial.md renamed to exercises/inverse-factorial.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
### Question - Inverse Factorial
2+
3+
In mathematics, the **factorial** of a integer n, denoted by n!, is the product of all positive integers less than or equal to n.
4+
5+
Write a function that returns a number if its factorial is given.
6+
If the input value does not have a solution, return 0.
7+
8+
Example:
9+
```
10+
input : 120
11+
output : 5
12+
```
13+
114
### Answer - Inverse Factorial
215

316
We create a loop counting from one to infinite. And in every loop we check that if number can be divided without remainder and multiply the products until we reach to input value.
@@ -40,5 +53,3 @@ function output = reverse_fact(input)
4053
output = i;
4154
end
4255
```
43-
44-
_Go to [question](https://github.com/enesdemirag/programming-exercises/blob/master/questions/inverse-factorial.md)._

answers/linear-regression.md renamed to exercises/linear-regression.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Question - Linear Regression
2+
3+
todo
4+
15
### Answer - Linear Regression
26

37
```python
@@ -22,5 +26,3 @@ plt.plot(x, line, "r-")
2226
plt.legend(["Estimated Line", "Data Points"])
2327
plt.show()
2428
```
25-
26-
_Go to [question](https://github.com/enesdemirag/programming-exercises/blob/master/questions/linear-regression.md)._

answers/mass-spring-damper-simulation.md renamed to exercises/mass-spring-damper-simulation.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Question - Mass Spring Damper Simulation
2+
3+
todo
4+
15
### Answer - Mass Spring Damper Simulation
26

37
```python
@@ -28,5 +32,3 @@ def set(time):
2832
# Create Simulation
2933
Visualizer(callback=set, interval=dt * 1000.0, simulation_time=20.0, initial=(position, 0, velocity, 0, acceleration, 0))
3034
```
31-
32-
_Go to [question](https://github.com/enesdemirag/programming-exercises/blob/master/questions/mass-spring-damper-simulation.md)._

0 commit comments

Comments
 (0)