22nd December 2016

Someone on Reddit pointed out that today (Dec 22nd) is Ramanujan’s 129th birthday. One of the commenters further pointed out that 129 is the sum of the first 10 primes, and the smallest number that is the sum of three squares in four different ways (echoing Ramanujan’s comment on G.H. Hardy’s taxi number 1729 being the smallest […]

1st October 2015

The number guessing game incorporates several simple but important elements of elementary programming and is a good candidate for an introductory programming example. If you’ve seen any programming course, you’ve probably seen the “Hello World” program. In Python it’s: print (“Hello World”)This is done to get the student(s) quickly to the point of having successfully installed […]

24th August 2015

Sorting is probably the most common type of algorithm in programming. A sorting algorithm puts elements of a list in a certain order. The most-used orders are numerical, and alphabetical. It’s extremely useful in many applications, because sorted data can be searched or merged very quickly (e.g. by binary search). A sorted data set is one where every item […]

4th July 2015

A variation on the Stars and Stripes American Flag for Independence Day. It’s an exercise in the use of transparency in Pygame. The stripes are made transparent so the stars image behind shows through.

1st June 2015

My favourite tweeter is Clifford A. Pickover. His tweets are delightful nuggets of math, physics & more. I have a copy of his fascinating The Physics Book. However, in these tweets, he claims that the string 44899 first occurs in pi at position 44899, counting from the first digit after the decimal point. I thought it might be […]

26th May 2015

This is simply a dictionary of Python keywords, implemented as – of course – a Python dictionary! Dictionaries are key:value pairs. The value can be any object, such as a tuple of strings. The first item in the tuple is part of the URL to documentation at Python.org, and the second item is a brief […]

7th May 2015

Graphs (also known as charts) are an indispensible visual aid for conveying a lot of data in an easy-to-digest form. Everyone is familiar with graphs in everyday life, such as those showing trends over time, e.g. world population, global warming, the cost of living, interest rates, etc. They are of fundamental importance in the STEM […]

18th April 2015

A colourful random walk. The basic idea is very simple: choose a random heading in the range 0:360 degrees. Step in that direction. Choose another random heading & step again. Do this 2,000 times. As a bonus, we go through all the colours of the rainbow (or something similar) from beginning to end. Dealing with […]

18th April 2015

This is a classic fractal drawn with a recursion algorithm and Turtle graphics. The Sierpinski Triangle’s sides are bisected and the triangle they form is removed. The procedure is then applied to the 3 remaining triangles, and to them recursively or until the Universe ends. Note that the use of recursion allows the code to […]

17th April 2015

This is your basic Mandelbrot Set plotter. Very little effort made to speed it up, except for plotting top & bottom pixels together as they’re mirrored across the x-axis. Later I’ll show you some much faster programs! The heart of this program is the iteration of z2+c where c is a point in the complex […]

16th April 2015

This is apparently a well-known interview question (but not one I was ever asked). Print the numbers 1 to 100, but replace every number divisible by 3 with “Fizz”, every number divisible by 5 with “Buzz”, and every number that’s divisible by both 3 & 5 with “FizzBuzz”. Apparently many people have difficulty with it. […]