1729 = 2 Cubes 2 Ways

Ramanujan’s 129th Birthday

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 […]

Guess my number?

Number guessing game

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 […]

Sorting Algorithms

Popular Sorting Algorithms

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 […]

Stars & Stripes

Stars and Stripes

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.

Pi by J.Gabás Esteban

Playing in Python with Pickover’s Premise per Pi

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 […]

Python dictionary

A Python Dictionary

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 […]

http://en.wikipedia.org/wiki/User:Wvbailey

Dr. Turing’s Automatic Machine

14th May 2015

Alan Turing published a ground-breaking paper in 1936, On computable numbers, with an application to the Entscheidungsproblem (PDF). It was about an esoteric problem in mathematics, for which he needed a theoretical model of how a mathematician computes with pencil & paper. He called this model an automatic machine; we now call it a Turing Machine, which […]

Easy Graph Plotting with Pyplot

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 […]

Binary Search

27th April 2015

Binary Search is one of the most fundamental computer algorithms. Given an ordered list of some data (names, numbers, …) find out if it contains a particular item. For example, consider the list: 2, 4, 5, 7, 8, 11, 12. If we ask if it contains the number 5, the algorithm should return 2 (counting […]

Random Walk

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 […]

Sierpinski Triangle, drawn by a Turtle

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 […]

Naive Mandelbrot Set

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 […]

FizzBuzz

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. […]