Skip to content

Instantly share code, notes, and snippets.

@maufirf
Last active April 22, 2019 11:43
Show Gist options
  • Save maufirf/1f3b8e865fe8ee20e6aae1b7feaba7bf to your computer and use it in GitHub Desktop.
Save maufirf/1f3b8e865fe8ee20e6aae1b7feaba7bf to your computer and use it in GitHub Desktop.
A help on the OS110 Exercism essay, ported from Discord.

1. PREPARE YOUR FILES

I assume you have finished 5 medium exercism challenges. Copy the folders into a separate folder, so it look like this (for example) :

5 completed exercises0

now, you have to delete the target folder in each of the folders, for example, in anagram folder above, the folder look like this:

Inside anagram folder

just simply delete them

Delete the target folder

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

New repo

Then Type a short, memorable name for your repository. For example, hello-world. (mine's OS110_MediumExercism)

New repo name

Then Select Initialize this repository with a README.

Select "initialize this repo with a readme"

Once done, click on the Create Repository. This is how it should look like after it is being made:

Afterclick preview

look back and click the "Upload File"

Click on "upload file"

then upload your files by simply drag and drop the 5 folders

Upload the 5 folders

while it is uploading, scroll down and fill the descrription, After the upload is done, click on Commit Changes:

Click on commit changes for the repo

finished, now go back to the main page.

2. WRITING ESSAYS IN THE README.md FILE

Open the README.md by simply clicking on the filename:

Click on the README.md file

it should probably look like this:

it should probably look like this:

Click on the pencil icon to edit the README.md:

Click on the pencil icon to edit the README.md:

now it should look like this:

The readme.md screen

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.

First

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)
}

Second

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

telling everything on the text:

## 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

putting your code literally, with comments:

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

interpreting your code as a pseudocode:

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:

Raw markdown README.md

is turned into something like this (See it in the github gist!):

Githubgist README.md

3. MAKING github.io PAGES

Mr. Eka heavily emphasizes that we should publish it in (github.io)[https://pages.github.com/]:

Mr. Eka's Quote

An essay to explain the approach and solution to a Medium level problem you choose. It must be published on Github.io

First,

go back to the repository main menu.

Back to the repo main menu

Second,

Click on the Settings:

Click on the settings button

Scroll down until you found this:

The github pages panel

Third,

Click on Change/Choose Theme:

Click on choose theme

It should look like this: Github pages theme selection

Fourth,

Choose your favorite theme

Theme 1

Theme 2

If you're happy with your theme, just click Select Theme:

Click on select theme

There should be two notifications after you clicked Select Theme, first in the top left corner:

Topleft corner notification

and second in the Github pages section:

Other notification in 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:

https://parampaa2.github.io/OS110_MediumExercism/

Good luck y'all buy me a rocky pls it's pretty tiresome to write this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment