# My Journey Through CS50x

## As a newbie CS student

It’s no secret to those seeking to learn CS or programming basics that Harvard has one of the best (and toughest IMO) courses for that. CS50x is an online variation of the on campus course that you can take anytime, based on Harvardx program. It also provides a certification to any that complete the course material, or you can go further and get a Verified Certification through EDx. Not like that matters, because the knowledge and portfolio you build is way more important.

I’m a big home studying fan, and pleased with the new opportunities that pop every day in…

# CS50x Runoff

## From problem set 3

Runoff is a ranked choice voting system. It has the benefit to provide a winner that better reflect the voters’ preference. To make that work, each voter rank the candidates in a preference list. If any candidate has a majority of the first vote preference, that candidate is declared the winner. If no candidate has more than 50% of the votes, an instant runoff takes place. The candidate that received the least amount of votes is eliminated from the election, anyone that had previously selected that candidate as their first preference now has their second preference considered. …

# CS50x Plurality

## From problem set 3

Plurality is a fairly simple introduction exercise to the next on the problem set, either you choose the less comfortable route with Runoff or the more comfortable with Tideman.

In Plurality we need to organize a simple election. The main function and headers are given by the course as a distribution code. We can’t change the distribution code or else we fail the staff tests. Our task is to implement the function that updates the voting count for each candidate and the function that print out the winner, or winners, as this simple model of election allows for frequent ties…

# CS50x Substitution

## From problem set 2

This time we’re preparing to code a substitution cipher. Instead of getting a number for key, we’ll be getting a string. A 26 character long string to be more exact, where each character will replace it’s equivalent index on the alphabet.

“A key, for example, might be the string `NQXPOMAFTRHLZGECYJIUWSKDVB`. This 26-character key means that `A` (the first letter of the alphabet) should be converted into `N` (the first character of the key), `B` (the second letter of the alphabet) should be converted into `Q` (the second character of the key), and so forth.”

`\$ ./substitution YTNSHKVEFXRBAUQZCLWDMIPGJOplaintext:  HELLOciphertext: EHBBQ…`

# CS50x Caesar

## From problem set 2

Although it may be obfuscated by the salad, the real Caesar did have his fair share of inventions. One of them, supposedly, is a simple cryptography system that consists in adding a number, or “key” to a letter, transforming it on another letter. A jump of positions based on said key. Here’s a working code example of “Hello” with key = 1.

`\$ ./caesar 1plaintext:  Hellociphertext: Ifmmp`

Unencrypted text is generally called plaintext. Encrypted text is generally called ciphertext. And the secret used is called a key.

So, how it works for the code we’re supposed to write?

## From problem set 2

Readability applies The Coleman-Liau index formula to a text. The Coleman-Liau index of a text is designed to output what (U.S.) grade level is needed to understand the text. The formula keeps track of letters, words and sentences to return that index.

`index = 0.0588 * L - 0.296 * S - 15.8`

Here, L is the average number of letters per 100 words in the text, and S is the average number of sentences per 100 words in the text.

Here’s an example output:

`\$ ./readabilityText: Harry Potter was a highly unusual boy in many ways. For one thing…`

# CS50x Credit

## From problem set 1

Credit is the point where things start to get complicated. We need to work with a lot of big numbers and not only do mathematics with then but learn how to travel trough the number to access specific digits in its composition. We learn a little about the cryptography behind each card number and how to use it to check if the card is valid and from which provider it comes.

As always we begin preparing our directory. Assuming you already have the pset1 directory, let’s type on our terminal:

`~/ \$ cd pset1~/pset1/ \$ mkdir credit~/pset1/ \$ cd credit~/pset1/credit/…`

# CS50x Mario

## From problem set 1. Both less and more versions.

On Mario problem set we need to create a terminal version of the famous pyramids from Super Mario World. The catch is that the pyramid must be responsive to the user inputs. He is deciding it’s height.

# CS50x Cash

## From problem set 1

Cash is the easier project we work on the entire course (provided you’re using the CS50 library). It basically asks us to count how many coins we need to use to return a change. Here the cashier wants to use the least amount of coins possible, not mattering how many coins of each are in the cashier’s drawer.

To begin, we open CS50 IDE through the Menu in the course page or by typing ide.cs50.io on your browser. Then procced to create our cash project folder.

`cd ~/pset1mkdir cashcd cashtouch cash.c`

You’ll notice that now we have…

## Guilherme Pirani

Get the Medium app