, , , , , ,

Course: Harvard’s CS50

Problem Set 1: C

pset1/hacker1 is an introductory assignment to get your feet wet in C.


Demonstration of how someone can use binary search to make a correct guess (find a target value) faster than linear search.

skittles.c (view | download)


A quick look at a simple ‘greedy’ algorithm.

greedy.c (view | download)


Make a horizontal chart.

chart.c (view | download)

Chart (hacker1)

Make a vertical chart.

chartv.c (view | download)

Credit (hacker1)

Check for ‘apparent’ validity of credit card numbers.

One small detail that had me scratching my head in hacker1′s ‘Bad Credit’ assignment was something I missed the first, second and third time I read through the text…

Okay, let’s multiply each of the underlined digits by 2 […]
Now let’s add those products’ digits (i.e., not the products themselves) together

Meaning: if the multiplication result is > 9 add the result’s digits together.
(ie. 2×8=16 –> 1+6 = 7)

That little hint probably got you going, and you can take care of the rest of the code yourself.

credit.c (view | download)


These examples go beyond what you may be required to know at this point and/or the pset specifications.

skittles2.c (view | download)

change2.c (view | download) Note: greedy.c for Euro coins.

chartv2.c (view | download)