Skip to content

If you knew …, then you could work out …

Jim Randell has developed a neat generic subroutine called filter_unique that can assist teasers of the form “if you knew X, then you could work out what Y is”.   He has made this and other useful routines for solving teasers available in his enigma.py library, which is also available here.   I call my version of Jim’s subroutine partition_unique because ‘filter’ implies for me that the output returns only a part of the input whereas ‘partition’ implies that the output divides the input into parts. My version is as follows:

It is available here.

An interesting aspect of this implementation is that it uses the original coding that I adopted soon after seeing Jim’s initial version. However, I abandoned this version in favour of Jim’s because mine had the undesirable property of not maintaining the order of elements in the input sequence in its output sequences. This was the result of the fact that Python dictionaries did not then return keys in a specified order.

But this has now changed in Python 3.6 and it has recently been announced that dictionaries in future versions of Python will return their keys in insertion order, a new feature which neatly removes the weakness that had caused me to drop my original coding for this routine.

Examples of Use

Here is a teaser that illustrates the use of partition_unique:

—————————————————————————
Sunday Times Teaser 2857 by Danny Roth

Published June 25 2017

Significant Errors

Last year George and Martha were going to visit one of their daughters. Her
house number was a two-figure number but unfortunately Martha wrote the
number incorrectly by making the first digit less than it should be. When
George discovered the error he commented that the incorrect number was a
whole number percentage of the correct one. If you knew that percentage
then you should be able to work out their daughter’s house number.

Then the daughter moved to a different two-figure house number, Martha
again wrote the number incorrectly by making the first digit less than it
should be, and again the incorrect number was a whole number percentage of
the correct one. If you knew that percentage then you should be able to
work out their daughter’s new house number.

What was the daughter’s original house number, and what is the new one?
—————————————————————————

which can be solved as follows: