Python Programming for the Puzzled

In this course, we use Python to solve a variety of puzzles. Two of the puzzles involve the game of chess. (Image by Brett Paci at MIT OpenCourseWare.)

By Joe Pickett, OCW Publication Director

Python Programming for the Puzzled

Those Sudoku number grids that look so easy but can be so exasperating—wouldn’t it be great to write a program that can solve every one of them?

Imagine you’re a magician, and your neat trick is to read the minds of the people in the audience. They’ve seen some cards pulled from a deck. You boast that you can read their minds and pick the fifth card, which is amazing, because you’ve already missed the first four! How can you pull this trick off?

The bike rack on your car has gotten loose and needs to be re-secured. All you need is a bolt and a nut that match the size of a hole in a metal tube. Luckily, you’ve got lots of bolts and nuts in a couple of jars on a shelf. Maybe it’s finally time to see which bolts and nuts fit together. But you don’t have all day. You need to get this done quickly. You’re meeting up with friends  . . .

Solving Algorithmic Puzzles with Python

These vexing challenges might seem about as different from each other as can be, but the puzzles they present are all solvable by algorithms and a little Python programming!

That’s right—you can program magic, and mechanics, and Sudoku grids right from your home computer. All you need is a little help from Professor Srini Devadas, now available in his course 6.S095 Programming for the Puzzled.

Taught during the IAP period of January 2018, the course has on its OCW site full video lectures, a prose description of each puzzle challenge, the necessary Python code, and the solution to the puzzle.

Professor Devadas is a master at making programming fun by tying it to real-world conundrums. He’s won an MIT MacVicar Fellowship for being such a great teacher, and in this course he’s at the top of his game.

Professor Srini Devadas begins his explanation of how he “read” the minds of the class in the “You Can Read Minds” puzzle.

There’s a square courtyard you have to tile. It should be an easy job, only the tile you’ve been given isn’t square. It’s L-shaped. And there’s this statue that you’ll have to work around. Don’t fret! Professor Devadas has the magic formula!

How can you place eight queens on a chessboard such that no queen attacks any other? How about if you have a chessboard of any size and a number of queens matching that board’s number of columns or rows? You don’t have to be a chess master to solve this one!

Professor Devadas knows how to foster creative thinking with programming, and the puzzles he unravels will surely lead his students to solve even more mind-bending puzzles in the future.

More Introductory Computer Science

A visualization of clusters found by a clustering algorithm.

By Joe Pickett, OCW Publication Director

Back in February we told you about a new OCW course in computer science, 6.0001 Introduction to Computer Science and Programming in Python. It’s a true introduction, for students with little or no programming experience.

Now you can develop your newly acquired skills further with the 2nd module in the sequence, 6.0002 Introduction to Computational Thinking and Data Science. It picks up where 6.0001 left off, providing you with “an understanding of the role computation can play in solving problems and to help students, regardless of their major, feel justifiably confident of their ability to write small programs that allow them to accomplish useful goals.”

The OCW site has full video lectures, featuring Professors John Guttag and Eric Grimson, along with lecture slides and supporting code, problem sets (so you can try out what you’ve learned), and files to install the latest version of Python, version 3.5.

Topics include Optimization Problems, Stochastic Thinking, Monte Carlo Simulation, Understanding Experimental Data, Introduction to Machine Learning, and Clustering.

This module offers a fresh approach to teaching how to think like a computer scientist. It joins our collection of Introductory Programming courses from MIT’s Electrical Engineering and Computer Science department, and is sure to join 6.0001 as one of OCW’s most visited courses.

New Computer Science Courses!

A blue and yellow fractal image.

A fractal generated from the hailstone sequence, as discussed in Lecture 1 of 6.005 Software Construction. (Public domain image from Wikipedia.)

By Joe Pickett, OCW Publication Director

One of the great strengths of OCW as an educational resource is its extensive list of course sites from MIT’s Department of Electrical Engineering and Computer Science. You might think, with so many courses published from the EECS curriculum, that OCW’s work for this department has reached a plateau.

But OCW continues to climb higher, augmenting and refreshing the course list, and two new publications present superb cases in point.

Learning to Think Like a Programmer

6.0001 Introduction to Computer Science and Programming in Python represents MIT’s evolving approach to this core subject, in which students with little or no programming experience learn how to write small programs that accomplish useful goals. 6.0001 is a six-week module using the Python 3.5 programming language.

Screenshot from video, of woman speaking in front of a chalkboard, holding a laser pointer.

Dr. Ana Bell explains a Python programming example (“robot cheerleaders”) in 6.001 Lecture 3.

The course site, showing the Fall 2016 class, has full video lectures featuring Dr. Ana Bell and Professor Eric Grimson. Slides and code for each lecture are also provided, as are interactive in-class questions with videos showing the answers to those questions. The textbook for the course was written by Professor John Guttag, who is well known to OCW fans for his popular OCW Scholar course, 6.00SC Introduction to Computer Science and Programming. The 6.0001 assignments page has helpful links to the 6.0001 Style Guide and a handy list of programming resources, including the Python Tutor.

Learning to Construct Software

Students who have developed some programming skill might then move on to 6.005 Software Construction, as taught in Spring 2016 by Professor Rob Miller and Dr. Max Goldman. As the instructors say in the syllabus, the course “introduces fundamental principles and techniques of software development, i.e., how to write software that is safe from bugs, easy to understand, and ready for change.”

Image containing some notes and a bubble+lines graph.

“Graphs—what are they good for? Poetry!” A page section from the problem, “Poetic Walks,” in the 6.005 Assignments.

An advocate of active learning, Professor Miller has his MIT students read a carefully structured textbook before coming to class so that most time can be spent doing exercises. The OCW site includes the full set of class readings, along with problems sets and a project, the ABC Music Player.

6.005 uses the Java programming language, for which help is available via the 6.005 Getting Started page and OCW’s popular course on Java, 6.092 Introduction to Programming in Java.