Skip to content

About

Objective

This is a site for people who have an interest in using the Python programming language to solve the mathematical and logic puzzles published weekly by the Sunday Times in the United Kingdom.  My intent here is to focus much more on Python than the teasers themselves, which means that if your interest is the reverse, this site is probably not for you.  If so, I recommend either the Sunday Times Teasers Discussion Group for manual solutions or Jim Randell’s S2T2 site for programmed approaches.

Intended Audience

I intend to keep the focus here on two groups of people:  firstly, young people who are taking up programming for the first time at home or at school and, secondly, people who probably learnt to use BASIC in the 1970’s on their first home computers and are now interested in moving to something that is just as easy to learn but is more in line with modern programming language concepts.

If you are an experienced programmer, it is very unlikely that you will learn anything new here; but you can help in meeting my objectives by posting example code that illustrates the use of Python for solving teasers.  But please remember that the focus here is on Python and on encouraging its take up in my two target groups.   And this has consequences for the sort of posts you should make.

Code Philosophy and Style

Firstly, given the target audience, it is important to post neat, well commented and reasonably efficient Python code.   In particular it should be comprehensible for people who are learning Python or are relatively new users of it.  Posted code should hence stay close to the Python PEP8 Style Guide [1](except for the use of the two space indents needed here to conserve horizontal display space).  Obfuscated code – deliberate or otherwise – is not acceptable and will be deleted!

There will, of course, be occasions where other external libraries will be useful but it is important that these are domain specific and available for installation using PIP. Examples include matplotlib for plotting and mpmath, numpy, sympy and scipy for scientific and mathematical work.  There are also libraries that extend Python by adding features not provided by the standard library such as sorted containers, polynomials and multisets.

However libraries such as Jim Randell’s enigma.py that aggregate lots of small ‘standard’ routines together with routines specifically designed for solving teasers should not be used here.  Jim’s library is perfect for its intended purpose – solving teasers – but it is far from perfect here because it hides much of the interesting Python code that needs to be visible on this site inside the library with the result that the code actually posted will often provide little in the way of Python insights and sometimes won’t even look like Python.   I stress that this is NOT a criticism of Jim’s library but rather a belief on my part that its use is not consistent with my objectives for this site.

Posting Python Code

When Python code is posted, syntax highlighting can be applied by putting <pre> before your code and </pre> afterwards. Please use Python 3 with spaces rather than tabs.  Please don’t post teaser answers in your code since the aim here is to encourage people to use Python to find the answers, not to have them dished up ‘on a plate’ for all to see.

IF you find that your code has become corrupted when you post it, you can send a copy to me and I will post it correctly. If this happens frequently, instead of posting your code in directly, you can instead click on ‘Crayon’ above the posting window. This will bring up a window in which you can post your code without it becoming corrupted.

Posting Mathematics

I am using MathJax to format mathematics on this site and this facility is also available in comments. The initial and final delimiters for display equations are a backslash followed by [ and ]; for inline equations they are a backslash followed by ( and ). For example:
\[i\hbar\frac{\partial}{\partial t}\left|\Psi(t)\right>=H\left|\Psi(t)\right>\]

However, getting LaTex maths expressions right first time is near to impossible so people who do wish to post such mathematics in comments will need to find a way to validate their Latex expressions before posting.

[1]  The Wing IDE, which is free for personal use, is excellent and has a command that will format code to align with PEP8. There is also an on-line PEP8 checker here (although this cannot be adjusted to cope with two space indents).