Pset1 in the books!

CS 50 Rules!


The first problem set (Pset1) is done.

I've completed the first week of what an 18 year old at Harvard does along with three other classes. The only thing that's different is that I am 43 years old with three kids, a house payment and two cars. And it took me two weeks to get it done.

Writing a program completely in "C" is very foreign to me. I've written some Javascript and Ruby, so I'm not completely new. But this is a different way of thinking about the problems. The challenges are not difficult to program once you take a step back and write down an outline of what you want the program to do. I'm super excited about this because for the first time I'm feeling like I'm really programming and not just copying and pasting something that someone else wrote.

The first problem set comes with four challenges:

  • hello.c
  • water.c
  • mario.c
  • greedy.c

I'm sure there are better ways solve these problems than I did, but this is just the first step in the learning process.

greedy.c

I spent way too much time on this one. I kept trying to figure out how to loop through the change requirements and use a different variable each time. I was thinking that I had to use loops to get the problem done, but then I decided to keep it simple and solve for each number of coins individually while also checking for the remainder with the modulus operator. I also used the floor() function from the math library to round down to the nearest integer. I used this since I knew I would be using the modulus operator to find the remainder (%) from the remaining coins from the previous coin. This doesn't sound like it makes sense, but if you read the code (I hope) it'll become a little more clear.... I'm sure there are better ways to do it and I look forward to seeing some elegant solutions! Cheers!

@russellbrownco!

comments powered by Disqus

Subscribe to my mailing. It's just fun stuff.

* indicates required