**From New Scientist #2189, 5th June 1999**

Samantha and Douglas are counting the squirrels visiting their garden. They record the monthly total for each of the 15 months January 1998 to March 1999. Samantha calculates that the number of squirrels is increasing, for she divides the 15 months into three five-month periods and finds the five-month totals are increasing with time. For example, there were more squirrels June to October 1998 than January to May 1998. But Douglas says the number of squirrels is decreasing, for he divides the 15 months into five three-month periods and finds the three-month totals decreasing with time, for example there were fewer squirrels April to June 1998 than January to March 1998.

1. Could there have been a total of 4 squirrels for the two months April and May 1998 and fewer than 75 squirrels for the whole of the 15 months? If so, how many squirrels were there for the 15 months?

2. Could there have been a total of 5 squirrels for the two months April and May 1998 and a total of fewer than 65 squirrels for the 15 months?

3. Could there have been 107 squirrels in June 1998 and 100 squirrels in October 1998? If so, how many squirrels were there in the 15 months?

4. Could there have been 108 squirrels in June 1998 and 100 squirrels in October 1998? If so, how many squirrels were there in the 15 months?

[enigma1033]

### Like this:

Like Loading...

I used

MiniZincmodels for each of the four questions. As they are all similar I wrote a Python program to generate and execute them using theminizinc.pywrapper.This Python 3 program executes in 469ms.

Solution:(1) No; (2) Yes. 60 total visits; (3) No; (4) Yes. 1560 total visits.I split the time period into:

Then S sees increasing visits using 5 month chunks:

and D sees decreasing visits using 3 month chunks:

There is a solution for question (2) when:

Which gives:

Adding 100 visits to each month then gives a solution for question (4):

and these are the only solutions.

There are two cases to consider:

By manipulating the inequalities we can come up with bounded expressions for the unknown variables.

Here is a Python program bases on this approach. It runs in 75ms.

Run:[ @repl.it ]Note that in the standard implementation of Python you cannot go on nesting [[

for]] loops indefinitely. There is a hard coded limit of 20 nested blocks in the Python interpreter. Although this restriction does not seem to apply to thePyPyimplementation.