Blog

A blog of Python-related topics and code.

Modular arithmetic on a circle

Inspired by David Richeson's applet on GeoGebra the Python script below plots the lines joining pairs of points, evenly spaced on the perimeter of a circle according to the following algorithm: label the $n$ points $k=0, 1, 2, \ldots n-1$; then join point $k$ to point $mk\,\mathrm{mod}\,n$.

The Goat Problem

A goat is tethered on the perimeter of a circular paddock of grass by a rope of length $r$. What should $r$ be to allow the goat to graze on a maximum of half the area of the paddock?

Maurer Roses

A Maurer rose is a shape formed by connecting the points on a rose defined in the polar coordinate system by $r = \sin(n\theta)$ for some positive integer, $n$. The points to join are, in polar coordinates using degrees:

New York Times Spelling Bee solver

The New York Times publishes a daily puzzle, Spelling Bee, in which players must find as many words as possible using seven letters arranged in a hexagon. Each letter may be used any number of times but the solution words must be at least four letters long and must include the letter at the centre of the hexagon.

QR Codes and the Game of Life

The following code identifies a QR code in a provided image and plays John Conway's Game of Life with it. It uses OpenCV (for image recognition and QR code detection), along with SciPy, NumPy and Matplotlib. If you don't have them, they can be installed with