I assume you have finished 5 medium exercism challenges. Copy the folders into a separate folder, so it look like this (for example) :
now, you have to delete the target
folder in each of the folders, for example, in anagram
folder above, the folder look like this:
just simply delete them
And repeat it for 4 other folders.
Now, you have to upload those folders into a new github repository. If you don't know, click here to read more, or just follow current section.
You have to log in to github first. if done, click the + symbol in the upper-right corner and click new repository
Then Type a short, memorable name for your repository. For example, hello-world
. (mine's OS110_MediumExercism
)
Then Select Initialize this repository with a README.
Once done, click on the Create Repository
. This is how it should look like after it is being made:
look back and click the "Upload File"
then upload your files by simply drag and drop the 5 folders
while it is uploading, scroll down and fill the descrription, After the upload is done, click on Commit Changes
:
finished, now go back to the main page.
Open the README.md
by simply clicking on the filename:
it should probably look like this:
Click on the pencil icon to edit the README.md
:
now it should look like this:
just edit the content, the syntax follows the cheatsheet written in this github gist. Seriously, read it, that's the easiest cheatsheet i ever found for github markdown.
If you're still desperate on how in earth you should write the essay, it is not that hard, just fucking try, but here is it anyway.
choose your favorite problem among the 5 problems you previously finished. For example, i have this function for an unexisting problem in exercism, let's say, the problem is to check how many even numbers given in an array, named "Even Counter". The final solution looks like this:
pub fn how_many_even(input: Vec<u32>) -> u32 {
input.iter().filter(|x| x % 2 == 0).fold(0, |acc, _| acc + 1)
}
Proceed to, well, explain it.
The beginning of everything, is to put the title, of course.
# Even Counter
elaborate on what is the problem. Define what is being given and what is the desired output. For example like this:
## The Problem
**Even Counter** is the problem where we are given positive integers inside a `Vec`, and we have to determine how many even numbers are inside the given `Vec`.
Then explain on how would you solve it at the first glance. I'd explain it like this:
I am thinking that this problem can be solved by:
- First, filter out the odd number from the `Vec`, so we only have even numbers left inside the given `Vec`,
- Second, Calculate the length of the filtered length
- Last, return that calculated value.
Then you just explain on how you actually solved it. Describe them technically, elaborate everything you know from the experiments or what you've read from the Rust's documentation.
There are several ways on doing this, first, by
## My Solution
Despite it being a `Vec`, we can use iterators to do it in one line without any `for`, `while`, or `loop` loops. We could start by turning the `Vec` into an `Iterator`, then using some other methods as described below:
1. `.iter()` converts the `input` `Vec` into an `Iterator`
2. `.filter(|x| x % 2 == 0)` filters the even value (that satisfies the logic `x % 2 == 0` in the closure) for the next calculation as `Iterator`
3. `.fold(0, |acc, _| acc + 1)` basically just sum on how many elements are present. `acc` is the accumulated value from previous iteration with inital value of `0`, and the underscore variable (`_`) is just the unused variable, it used to be each of the element inside the iterator (and i'm not using it. hence, the `_`.)
Or, second, by
Here is my code:
```rust
pub fn how_many_even(input: Vec<u32>) -> u32 {
input // The input Vec
.iter() // Convert to iterator
.filter(|x| x % 2 == 0) // Filter the even numbers
.fold(0, |acc, _| acc + 1) // Count total filtered elements
// Straight return in the end of line of the function
}
```
Or, maybe by
My above program can be interpreted as this pseudocode:
```rust
public function how_many_even(input Vec with u32 elements) -> The count of even number in u32 {
1. Prepare the input vector, put it as if it is going to be returned so no semicolons, neither the return statement
a. Convert the input vector to iterator
b. Filter out the even elements
c. Count the rest of existing, filtered elements
2. Return the count value
```
Or if you have other way to write/express it, just do it your way, these are just examples.
The last thing you should do is to conclude.
## Conclusion
From the exercise I presented above, it is obvious that Rust's iterators is a versatile tool to edit and return a collections operation in a single line without too much loopings like `for` and conditionals like `if`. *blablabla explain it etc, etc....*
after finish writing on README.md
, commit changes.
from the thing that looks like this:
is turned into something like this (See it in the github gist!):
Mr. Eka heavily emphasizes that we should publish it in (github.io)[https://pages.github.com/]:
An essay to explain the approach and solution to a Medium level problem you choose. It must be published on Github.io
go back to the repository main menu.
Click on the Settings
:
Scroll down until you found this:
Click on Change/Choose Theme
:
Choose your favorite theme
If you're happy with your theme, just click Select Theme
:
There should be two notifications after you clicked Select Theme
, first in the top left corner:
and second in the Github pages section:
You're Done! The generic form of the link is yourusername.github.io/yourrepositoryname, you can click it. For example, my site looks like this: