teaching machines

CS1: Lecture 30 – 2D Arrays and ArrayList

Dear students, Today we will complete a whirlwind tour through a couple of concepts that really deserve a couple of conversations each. These concepts are two-dimensional arrays and ArrayList. Two-dimensional Arrays Let’s consider a famous statistical problem. Suppose birthdays are uniformly distributed across the calendar year. What’s the probability that we in this room all […]

CS1: Lecture 29 – Bundled Data

Dear students, Last time we used arrays as a means to map integers to values. We associated our data with 0, 1, 2, 3, and so on. When we got a new piece of data in, we use its index to reach inside our array directly. Today we shine the spotlight on arrays as a […]

CS1: Lecture 28 – Indexed Data

Dear students, We officially close out our discussion of the Computer as a Pilot, during which we made the computer navigate this way and that way and back again through our code using conditional statements and loops. But, like always, these ideas of branching and repetition will never leave us. Computers make a lot of […]

CS1: Lecture 27 – BufferedImage

Dear students, In homeworks 4 and 5, we work with images. Loops are a natural companion to images, which are large collections of indexed data that we are not even tempted to process without loops. The general pattern of visiting all pixels of an image is this: for (int r = 0; r < image.getHeight(); […]

CS1: Lecture 26 – Looping Patterns

Dear students, So far we’ve used loops to traverse 1D spaces: the number line, files, and a sequence of random events like coin flipping. Today we bust out into 2D spaces, traversing images and other Cartesian grids. Nesting Loops To transition to our next concept, let’s write a program to mimic the activity we see […]

CS1: Lecture 25 – Loops Continued

Dear students, You know that trope in movies where someone invents a new technology? At first it seems to be doing going good, but then it starts to get out of control. That’s where we are in the semester. Our software up until this point was very mild and had a limited reach. Now we […]

CS1: Lecture 24 – For Loops

Dear students, While loops put a heartbeat in our code that makes it feel alive. We can feel the CPU pulse through our data while we sit back and await the result. But while is not the only way to make code repeat. Today we consider the for loop. For Loops Last week we broke […]

CS1: Lecture 23 – While Loops Continued

Dear students, Loops turn us into pattern hunters. Behind some complex output is a much simpler machine using repetition. Let’s keep building those repetitive machines today. We’ll keep exploring while loops. While Last time we introduced while. Let’s see it at work in a few more programs. Write a program that starts with a number […]

CS1: Lecture 22 – While Loops

Dear students, Today we extend the notion of a Computer as Pilot to not just yaw left or right as it navigates through our code, but to also swoop back around to code that it has run previously. But first we examine some situations where developers write conditional statements that they shouldn’t have written. If […]

CS1: Lecture 21 – If Ladders

Dear students, Our programs have completed optional work with the diversion pattern. Our programs have chosen between two actions with the bifurcation pattern. Today we look at the making n-way choices with the ladder pattern. Ladders Suppose you’ve got an app that measures the pH of something—the food your about to ingest, perhaps. You want […]

1 2 3 94