Welcome to CS21! My name is Jeff Knerr (pronounced "nerr"). I am teaching the MWF 10:30-11:20am section. This course is our "first course" in Computer Science (CS), so no prior knowledge of CS is required. If you have taken AP Computer Science in high school, or have a fair amount of programming experience, please come see me the first week to make sure you are in the correct class. This class is intended for majors and non-majors, but if you have significant programming experience, we may want to move you up to one of the next courses in CS (CS31 or CS35).
A little about me: I've been here at Swarthmore for 15+ years. I think I've taught this course at least 13 times. However, I am not, technically, a computer scientist. My background is in Physics and Astronomy. My research involved computer simulations and tons of programming, so I know how to write computer programs, and I've learned a little CS along the way. I am also the system administrator for the CS department. As for my teaching philosophy, I found these Ten Commandments for Good Teaching a few years ago and think they are excellent (thank you, Professor Patt!).
The goal for this course is, obviously, to give you an introduction to Computer Science. We do that by teaching you the python programming language, as well as some basic CS concepts. Each week we will learn something new, and then write computer programs (lab assignments) to help reinforce what we just learned. In addition to learning to program, and learning about CS, you will practice and learn problem-solving. Designing and writing a program, as well as getting it to run correctly, involves a lot of problem-solving. Hopefully, this is a skill that will help you in life, whether you go on in CS or not.
In addition to our section, there are two others, taught by Lisa Meeden and Joshua Brody. You may actually have Lisa or Joshua as a lab instructor.
We will also have ninja help in the lecture, labs, and study sessions. The CS21 ninjas are students that have already taken the course, and are here to help guide you through the process of learning to program. Our in-class ninjas are Reba Magier and Sonya Chen. You may also meet Lauri Courtenay this semester, our Academic Support Coordinator. Lauri manages the ninjas and helps us run the classes and labs.
Instead of trying to tell you what computer science is, and what this course will cover, I like to do an example the first day, so you can see it for yourself.
Let's look at a simple puzzle, called a nonogram. http://www.nonograms.org is a nice website that has puzzles you can solve. One of the puzzles (#4668, if you want to try solving it on the website) is shown here:
I have only solved a few of these puzzles, so I am not an expert. I started by reading the instructions on nonograms.org. Here's what I know so far:
To start solving the above puzzle, I would look for large row or column numbers. For example, consider the two columns with the 5's. If I know there must be 5 consecutive black squares in those columns, then, since the puzzle is only 7x7, the middle three squares in each column must be black, like this:
Does that make sense? The 5-in-a-row could either start at the very top, or the very bottom of the grid (or somewhere in between). Either way, the middle three squares will be black, so I can fill them in right now.
There's also a 5 in one of the rows, so we know, since there are already two black squares on that row, which 5 squares must be black. And since there has to be an X (or the edge of the puzzle) on either side of the 5 black squares, the puzzle must look like this:
I don't want this whole lecture to be on nonograms, but hopefully you can see, using logic, we can gradually fill in more and more squares, eventually solving the puzzle (try it!). Just for fun, do you see why my next step might look like this (Hint: see the 2 2 rows)?
Once we know that, the "2 3" column can be filled in, and so on...
Getting back to computer science, do you think we could write down all of the logic we've been using, into a series of step-by-step instructions, that someone like you or I could follow, that would allow us to solve any nonogram puzzle?
What we are searching for is called an algorithm: a recipe, or step-by-step instructions, that allow the computer (or a person) to do some task, like solve a nonogram, or play a good game of chess, or maybe just fill out your tax forms.
Back to the nonogram, can you come up with an algorithm for checking if a row or a column is valid or not? This might be a small part of the full game program.
For example, given this row, can you, just by looking at it, tell if it's valid or not? That is, do the sets of consecutive black squares match the row numbers?
It is surprisingly easy for us humans to glance at those numbers and black squares, and say, "yeah, that looks like it could be correct".
How about this one?
Can you write down the exact steps you are doing to decide if the black squares match the row numbers? Will your algorithm work for any row and row numbers?
Try this specific example: suppose you have some row numbers, say "1 3 2", and you also have a row of 15 boxes, all filled in, either black ("B") or with an "X", like this: "X X B X X X B B B X X X B B X". Write down the steps you take to decide if that's a valid configuration for those row numbers. Try to be specific!
Go ahead and take 5 minutes and try to write all the steps down on paper. I'm serious...don't read any further until you have a set of steps written down...I can wait. :)
Here's a picture of a cute puppy...to keep you from reading further, until you have your algorithm written down...
Now that you have an algorithm, try it on other row configurations, like these:
Does your algorithm work in all cases?
In case you got stuck above, here is a simple example of such an algorithm:
That algorithm is (hopefully) sufficient for you and other humans to understand. It is not, however, specific enough for a computer to understand. For example, how do we "move to the right" along the row? And where and how do we "store or save how many consecutive B's we saw"? Some of the problem-solving you will do this semester involves turning human-understandable algorithms into programs the computer can run.
The computer science part of all this is in developing and analyzing algorithms. Will the above algorithm work in all cases? And is it the best, most efficient way to solve the problem?
Most computer programs contain the following elements:
Your algorithm from above probably has most of these elements in it. For example, the inputs to your algorithm are the row numbers and the row of boxes. The output of your algorithm is either a "yes, that's valid" or a "no, that's invalid" statement. As you look at the contents of each box, you do something different if it's an "X" or a "B". That's a branch (and so are the last two "if" statements). We are looping over all boxes in the row, doing something for each box. All of the data for each row needs to be stored in some kind of structure where we can access each box and see what's stored there. Finally, to complete the program, all of this is tied together with the above algorithm.
The above nonogram puzzle is a good example of what we will do in this class. By the end of the course, you should be able to write a simple graphical nonogram puzzle/game, where the user clicks on boxes to either fill them in black or mark them with an "X". And once all of the boxes are filled in, your program could tell the user if the puzzle is correct or not.
Developing and analyzing algorithms is also what we will do in the course. Each week we will have lab assignments, where you must develop an algorithm and implement it in the python programming language. This includes testing your program, to make sure it works, and analyzing your algorithm, to make sure it is efficient.
For this week, you need to do the following:
vim
)If you have a Tuesday lab session, you will get your CS account and password during lab. If not, I will hand out the remaining accounts during Wednesday's class.
Let me know if you have any questions!