A guide to the ‘DNA’ problem in CS50 Week 6.

Goal: To write a python script that can identify someone from a database, based on their DNA sequence.

The script must be called with two additional command line arguments; a csv database containing the number of times that particular sequences of characters repeat in a list of people’s DNA sequences, and a DNA sequence .txt file that we will be analysing and assigning an owner to based on the database in the first argument.

The particular sequences in question are known as ‘Short Tandem Requests’ or STRs. …


A guide to the ‘Speller’ problem in CS50 Week 5.

Goal: To implement a spell checker program in C. The program is partially written, but we must write functions that both load and unload the dictionary into memory, as well as checking if each word in the given text is in the dictionary and thus spelled correctly.

The dictionary should be loaded into a hash table, which can be looked up when checking if each word is spelt correctly. The aim is to minimise this lookup time by using an appropriate hash function.

The functions to be defined within dictionary.c


A guide to the ‘recover’ problem in CS50 Week 4.

Goal: To write a program in C that can recover JPEG images from a forensic file.

The program must accept one and only one command line argument, the name of the file the images will be recovered from.

The program should output each of the JPEG images recovered as a separate file. There are 50 in total to be recovered from the card.raw file provided.

The first step is to import the correct libraries and define the BYTE struct, as recommended in the problem description for storing one byte of…


A guide to the ‘Filter’ problem in CS50 Week 4 (more difficult version).

Goal: To write a series of functions in C that apply various image filters to bmp inputs.

The grayscale function should take an image and turn it into a black and white version of the same image.

The reflect function should take an image and reflect it horizontally.

The blur function should take an image and turn it into a box-blurred version of the same image.

The edges function should take an image and highlight the edges between objects, according to the Sobel operator.

There are a…


A guide to the ‘Tideman’ problem in CS50 Week 3.

Goal: To write functions to determine the winner of a tideman election and to print the name of the winner. Before reading further it is important to understand how a tideman voting system works, which is explained in the problem description.

The vote function must take arguments rank, name, and ranks. If name is a match for the name of a valid candidate, then the ranks array should be updated to indicate that the voter has the candidate as their rank preference (where 0 is the first preference, 1 is…


A guide to the ‘Plurality’ problem in CS50 Week 3.

Goal: To write functions to determine the winner of a plurality election and to print the name of the winner.

The vote function takes a single argument, a string called name, representing the name of the candidate who was voted for. This function must return either true or false, depending on whether or not the name given matches any of the candidates in the election. If it returns true, it must also increase by 1 the votes value for that candidate.

The print_winner function must print out the winner of…


A guide to the ‘Substitution’ problem in CS50 Week 2.

Goal: To write a program in C that implements a substitution cypher, as per the below.

$ ./substitution JTREKYAVOGDXPSNCUIZLFBMWHQ
plaintext: HELLO
ciphertext: VKXXN

The program must encrypt only the letters, irrespective of whether they are upper or lower case.

$ ./substitution VCHPRZGJNTLSKFBDQWAXEUYMOI
plaintext: hello, world
ciphertext: jrssb, ybwsp

It must accept only one command line argument, the key to be used for the substitution. This key must be exactly 26 characters long, only accept letters and also be case insensitive.

It must then ask for the plain text and return…


A guide to the ‘Readability’ problem in CS50 Week 2.

Goal: To write a program that takes an input text and returns the grade level of complexity. This should be calculated using the Coleman-Liau Index, where L represents 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.

index = 0.0588 * L - 0.296 * S - 15.8

The program should behave like the below example, with ‘Text:’ acting as a prompt for the user to enter the text to be assessed.

$ ./readability
Text…


A guide to the ‘credit’ problem in CS50 Week 1.

Goal: To write a program in C that can validate credit card numbers using the Luhn Algorithm, and return whether a valid card number is Mastercard, Visa or Amex. The program must ask for the number and only accept numeric inputs, devoid of hyphens or other punctuation as per the example below.

$ ./credit
Number: 4003-6000-0000-0014
Number: foo
Number: 4003600000000014
VISA

If the card number fails the checks, the script should return INVALID.

$ ./credit
Number: 6176292929
INVALID

Disclaimer: while there are more efficient ways to do this, my solution…


A guide to the more difficult version of the ‘Mario’ problem in CS50 Week 1.

Goal: To write a program in C that outputs a pyramid of blocks (using the # symbol) of a given size, with a gap in the middle.

JR

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store