If Only I Had A Penny For Every Time…

Just a quick update on my foray into computer science and my studying of the CS50 open course ware at http://cs50.tv/2011/fall/

I am currently working on the problem set for Week One (course starts on Week 0, like a computer would), called Pennies. You have to write a script in the C programming language that calculate a user’s input of the month, and is based on the old wisdom tale of would you rather have a bag of money or start with a penny and your pennies double every day for a month? I think this is a take on a similar tale I heard from my father when I was a kid. Only in his example, it had something to do with Ancient China and a guy asking the king as payment if he could have one grain of rice on the first square of a chess board and which would double each square on the chess board. Of course the king laughed at him wanting rice on a chess board instead of gold or money, but if you do the math… that is a fortune in rice!

Now I am attempting the Hacker editions of the problem sets, so I also in addition to writing a C program that computes the pennies problem I have to also create a program that prompts a user for a credit card number and then determines if that credit card is valid or not, using an algorithm created by Hans Peter Luhn who was a Computer Science pioneer at IBM. But I won’t get into this problem set yet, I will explain it later when I get it to work correctly.

A third problem in the Hacker Edition is to create some sort of vertical bar chart, but I haven’t got that far yet, so, for those curious here is the basic instructions of the pennies.c problem set (more details in the PDF if you go to the cs50.tv site):

Implement, in a file called pennnies.c, a program that first asks the user how many days there are in the month and then asks the user how many pennies he or she will receive on the first day of that month. The program should then calculate the amount that the user will have received in total by the end of the month (not just on the last day) if that amount is doubled on every day but the first, expressed not as pennies but as dollars and cents, with dollars formatted with commas every three digits. If the user does not type in 28, 29, 30, or 31 for the number of days in the month, the program should prompt the user to retry. If the user does not imput a positive integer for the first day’s number of pennies, the program should prompt the user to rety.

For instance, your program might behave as follows, whereby boldfaced text represents some user’s input.

jharvard@appliance (~/hacker1): ./pennies
Days in month: 32
Days in month: 31
Pennies on first day: 1
$21,474,836.47

Advertisements

I Took CS50…

CS50 Harvard

… soon anyways!

Last week I started “taking” the Harvard CS50 Fall 2011 OCW course provided online by David Malan. It’s an introduction to Computer Science and Programming course. I am currently finishing up my ‘homework’ which is the problem set from Week Zero and you create a program using the Scratch application created by M.I.T. I decided to make a small pseudo-first person shooter game in which Lauren Bacall has to shoot her way through a bunch of peacocks… it made sense in my mind I swear!
What’s really cool is that I can take the class online with others, starting on October 15th via this site edX, created by MIT and Harvard (and now joining in is UC-Berkely) which provides online versions of real courses, for free:

https://www.edx.org/courses/HarvardX/CS50x/2012/about