A Christmas exercise for students

Translated from Polish. Originally published on morony.pl on 21 Dec 2016.

Every year, as Christmas approaches, I give the first-year students in my introduction to programming in Python a short in-class quiz with a no-brainer of a task: make a Christmas-themed plot. Christmas falls more or less when we get to the matplotlib library, so the task isn't much of a stretch content-wise either. The first time I gave this task, I was sure I was giving them a present in the form of a free point towards their grade. Unfortunately, every year there are people for whom coming up with the coordinates of the vertices of a polyline shaped like a Christmas tree is too hard.

The task has one more hidden purpose – it shows very nicely whether a given student is good material for a physicist-programmer:

  • Some people create every element of the "drawing" separately – even the parts of the tree are sometimes drawn as individual line segments. In such cases the stars / baubles are also drawn with many separate calls to plot(). The authors of such work usually have a hard time passing this simple introductory course.
  • The standard is a slightly more thought-out solution, where the vertices of the polylines and the extra elements are defined as lists. While the drawing approach itself may be well thought out, the coordinates are still typed into the code by hand. Most authors of such solutions have no trouble passing the course with a B.
  • The rarest and best solutions use some kind of mathematical rule: for example, a function that generates the coordinates of the tree-shaped polyline, taking the number of branches and the height as parameters. I've come across a solution like that no more than once a year. Its authors always pass with an A and have no trouble with the other (harder) courses.

The most important thing in this task is not to suggest either the end result or the way to solve it. That way it brings out creativity (or a complete lack of it) and subconscious programming skills: whether a person treats the computer as a blind executor of commands, or as a machine that can follow an algorithm.

I think this could be a very clever recruitment task. My students got 15–20 minutes to solve it. Here are a few examples: