Monday, 17 February 2014

Contest Center

Due to a prolonged spell of wet weather in the UK, and the demise of New Scientist Enigma, I have recently turned my attention to the Contest Center, which has a lot of interesting maths puzzles.

I concentrated on problems that did not yet have any solvers, and managed to solve a few of them. (hints under plain cover to genuine puzzle enthusiasts only)

Point on Circumcircle (contributed by Fotos Fotiadis) 
 ABC is a triangle whose smallest angle is A. K is a point on the arc BC of the circumcircle. The perpendicular bisectors of AB and AC intersect the line AK at L and M, respectively. The lines BL and CM intersect at T. Prove that BT+CT=AK. 


Greatest Divisor (contributed by Paul Cleary) 
When n=8, the expression ab(an-bn) is divisible by 30 for all positive integers a and b, and 30 is the greatest such divisor. Find a positive integer n such that the greatest common divisor of ab(an-bn) for all positive integers a and b is n. 


26 Numbers (Contributed by Paul Cleary) 
There are infinitely many sets of 26 real numbers where their sum is 200 and the sum of their squares is S. The difference between the smallest and largest of the numbers in these sets is 60/13. What is the value of S? 


Sums of Polynomials 
Let pi(x) = x2+mix+ni for i=1,2,3,4 be four given polynomials with mi and ni integers, and m1 through m4 not all odd. Show that there is an integer N such that any integer n > N can be expressed as the sum p1(a1)+p2(a2)+p3(a3)+p4(a4) for some integers a1 through a4. 


Rational Powers (contributing the criterion gcd(a,b,c)=1)
 Let x be a rational number x=p/q with q>1 and gcd(p,q)=1. Let a, b and c be positive integers, with ax+bx=cx and gcd(a,b,c)=1. Prove that a, b and c must be q-th powers, or find a counterexample. 



Repeated Digits  (not a first to solve, but most solutions found to date)
The square of 88 is 7744, where each digit of the square is repeated. Find additional squares (not ending with 0) where every digit is part of a repeated sequence, such as 11000555544. We will list the number of squares found by each solver. The notation +F indicates that the solver also found an infinite family of solutions. 

Update June 2014:
Square Heronian (contributed by Lee Morgenstern) 
A Heronian triangle has integer sides and integer area. Find a Heronian triangles where all 3 sides are squares. [Only one solution is known. Extra credit for anyone who finds a second solution.] 

Update September 2014:
** Square Rearranger 
Find the smallest three distinct whole numbers A, B and C such that you can rearrange the digits of A and B to get C2, the digits of A and C to get B2, and the digits of B and C to get A2. [Leading zeroes are not allowed.] 

Tuesday, 21 January 2014

New Scientist Enigma 1354: Sound idea

     Here is a solution to Enigma 1354 which appeared recently in Enigmatic Code

The problem is this:
Joe’s daughter has been asking him for weeks to make a wind chime. So this week Joe cut a length of stainless steel tubing into 10 lengths from 1 cm to 10 cm in steps of 1 cm. He also cut out a disc from a sheet of stainless steel and drilled 10 evenly spaced holes round the perimeter and one in the centre.

Joe hung one tube from each hole and hung the disc up by a thread from its centre. That was a big mistake as the disc tilted right over.

So Joe rearranged the tubes until the disc balanced perfectly. In making a note of the lengths of the tubes in order round the disc the result was an 11-digit number.

What is the smallest of all the 11-digit numbers Joe could have written down?

In order for the wind chime to balance, moments about the axis af must balance
$ (b+e-g-j)sin(\frac{π}{5}) + (c+d-h-i)sin(\frac{2π}{5}) = 0 $ ..................... (1)
Noting that $sin( \frac{2π}{5}) = 2 sin(\frac{π}{5}) cos(\frac{π}{5})$ , dividing (1) through by $sin(\frac{π}{5})$
$ (b+e-g-j) +2 (c+d-h-i)cos(\frac{π}{5}) = 0 $ ..................... (2)
Substituting $ cos(\frac{π}{5}) = \frac{(1+\sqrt{5})}{4} $ into (2)
$ b+e-g-j +\frac{c+d-h-i}{2} +\frac{(c+d-h-i)\sqrt{5}}{2} = 0$
As a,b,...,i,j are all integers,$ c+d-h-i = 0$ and $b+e-g-j +\frac{c+d-h-i}{2}     =0$

So $c+d=h+i$ and $b+e=g+j$

So knowing five adjacent values, say, a,b,c,d,e, allows the other five to be deduced:
$f = 55 - a - (b+c+d+e) - (g+h+i+j) = 55-a-2(b+c+d+e)$
And so on round the circle.

So, some code:

from itertools import permutations as perm

a=10
onetoten=frozenset(range(1,11))

for b,c,d,e in perm(range(1,10),4):
  f=55-a-2*(b+c+d+e)
  g=55-b-2*(c+d+e+f)
  h=55-c-2*(d+e+f+g)
  i=55-d-2*(e+f+g+h)
  j=55-e-2*(f+g+h+i)

  s=(a,b,c,d,e,f,g,h,i,j)
  if set(s)==onetoten:

    # sanity check
    if all( sum(s[i%10] for i in xrange(m,m+4))
            ==sum(s[i%10] for i in xrange(m+5,m+9))
            for m in xrange(10)):
      print "solution", a,b,c,d,e,f,g,h,i,j
      break

Saturday, 14 December 2013

New Scientist Enigma 152: The highways of Genoland revisited

Following my post on The highways of Genoland, Jim Randell pointed out that the original puzzle had missed a round trip, and that there are actually four round trips. The missing round trip uses highways 1,2,3,4,D (not necessarily in that order).

I wondered what a solution would look like if the fourth round trip had been included in the original puzzle:

As before, no pair of cities is connected by both a national and provincial highway. There are two possible configurations of connections that have eight connectors connecting five nodes:

Configuration A does not provide four round trips, so the five cities are connected in configuration B. We can immediately deduce which city is Geno:

The four  round trips 1,3,4,B,C;   1,2,A,C,D;   2,3,A,B,C;   1,2,3,4,D are in some order: 


Highways 1,2,3,C appear in three round trips (green). 4,A,B,D appear in two round trips (orange)

Geno is reached by the highways that appear in two round trips, namely 4,A,B,D


Friday, 13 December 2013

New Scientist Enigma 152: The highways of Genoland

This was a particularly tricky puzzle to solve with a computer algorithm, as demonstrated by Jim Randell's solution, so here is a manual solution.

The problem statement is:

The five cities of Genoland are interconnected by four national highways A, B, C and D. They are also independently linked by four provincial highways 1, 2, 3 and 4. Each highway connects two cities and Geno is the only city which can be directly reached from every other city. A round trip of the five cities involves the five highways 1, 3, 4, B and C or 1, 2, A, C and D or 2, 3, A, B and C (not necessarily in the order given).

Which of the highways reach Geno?

No pair of cities is connected by both a national and provincial highway (this can be deduced from the round trips). There are two possible configurations that have eight highways connecting five cities:
Configuration A does not provide three round trips, so the five cities are connected in configuration B. We can immediately deduce which city is Geno:

The three round trips are:  

Highway C appears in all three round trips, so we can deduce which highway is C. Highways D and 4 appear in only one round trip each, so we can also deduce 4 and D (national highways are blue, provincial are red)


Highway 1 is in the same round trips as highways 4 and D, so we can deduce highway 1:
As all cities are connected via provincial highways, the remaining highway from the top city must be a provincial. Similarly, as all cities are connected via national highways the remaining highway connecting the bottom right city must be a national:
The round trip using highway 4 uses highways 1,3,4,B,C, so we can deduce which highways are B and 3 :

Similarly, the round trip using highway D uses highways 1,2,A,C,D so we can deduce which highways are A and 2 :


So Geno is reached by highways A,B,D,4



Monday, 27 May 2013

Hamiltonian Cycles on a Square Grid, part 2

The algorithm in my first post on this topic used some of the ideas in  R. Stoyan and V. Strehl: Enumeration of Hamiltonian Circuits in Rectangular Grids. Journal of Combinatorial Mathematics and Combin.Computing 21 (1996), 197-127, but did not employ the construction technique suggested in their paper.

Here is a modified algorithm, with vastly improved performance, using most of the construction method suggested by Stoyan and Strehl.

The algorithm constructs all 1,072 Hamiltonian cycles on a 6 by 6 grid in about 100ms, and all 4,638,576 Hamiltonian cycles on an 8 by 8 grid in about 20 minutes. 

Here, the algorithm runs out of steam, as a 10 by 10 grid has 467,260,456,608 cycles (Sloane A003763)



To construct N by N Hamiltonian cycles, the algorithm builds up  "induced subgraphs" (see diagram at left) of an (N-1) by (N-1) square graph one cell at a time, starting with the top row and working across each row in turn.










The top row is constructed by observing that the corner cells have to be inside the Hamiltonian Cycle, and that no two outside cells can be adjacent.

From then on, cells are added by testing whether a cell can be inside or outside (or both or neither) according to the rule that no 2 by 2 block can be any of these patterns:



A 2 by 2 block $a,b,c,d$ will match one of the four patterns iff $a=d$ and $b=c$




Additional tests check that:
  • no 2 adjacent cells on the perimeter can be outside
  • the total number of inside and outside cells does not exceed   $\frac{N^2-2}{2}$ and $\frac{(N-2)^2}{2}$ respectively
  • After the completion of a row, all inside cells are connected to the row just completed.




Python implementation

Here is the Python code for the algorithm. 

Hamiltonians(N) yields all the Hamiltonian cycles for an N by N grid.

Tuesday, 21 May 2013

Constructing Hamiltonian Cycles on a Square Grid

Background

A solution to New Scientist Enigma puzzle 1431 led me to consider how to generate all Hamiltonian Cycles for an N by N square grid.

The obvious way to generate Hamiltonian cycles for any graph is to find all Hamiltonian paths that end at a node adjacent to the start node. However, for a 6 by 6 grid, there are 458,696 Hamiltonian paths but only 1,072 Hamiltonian cycles. (Sloane A096969 and A003763)
The analysis in  R. Stoyan and V. Strehl: Enumeration of Hamiltonian Circuits in Rectangular Grids. Journal of Combinatorial Mathematics and Combin.Computing 21 (1996), 197-127, identifies an alternative way of identifying Hamiltonian cycles.

For example, this figure shows a Hamiltonian Cycle for a 6 by 6 grid.

Stoyan and Strehl point out that each cell is either inside or outside the Hamiltonian Cycle, as shown here (yellow cells inside, white outside)

Thus, Hamiltonian Cycles for an N by N graph can be associated with an "induced subgraph" of an (N-1) by (N-1) square graph.

Stoyan and Strehl show that any induced subgraph corresponds to a Hamiltonian Cycle if:

A) It is a tree

B) No 2 by 2 sub-grid of the extended grid matches one of the four patterns:

  Additionally, there are always $\frac{N^2-2}{2}$ inside cells and $\frac{(N-2)^2}{2}$ outside cells, and the four corner cells have to be inside.

These constrants can be used to find subgraphs that correspond to Hamiltonian cycles more efficiently than the search of Hamiltonian paths. For N=6, there are $\binom{(N-1)^2-4}{\frac{(N-2)^2}{2}} = \binom{21}{8} = 203,490$ combinations of outside cells that need to be tested.

However, the algorithm does not scale well. For N=8, there are $\binom{45}{18} =  1,715,884,494,940$ combinations of outside cells.

The performance could be improved by using the observation that there cannot be 2 contiguous outside cells on the boundary. However the algorithm as it stands runs in less than 1 second for N=6, and the suggested improvement would not significantly reduce the number of cases that would need to be tested for N=8.

Python Implementation

A Python implementation of an algorithm based on these constraints is presented below. The search for the four patterns of 2 by 2 sub-cells does not cover the extended grid, as it turns out that this is not necessary, at least for the cases N=4 and N=6 (I haven't worked out whether this extends to higher values of N)

Tuesday, 7 May 2013

Dent, Aye Gill Pike

I camped at High Laning campsite in Dent on a very pleasant sunny evening, and next day walked a circuit from Dent along the ridge of Aye Gill Pike.

View from High Laning campsite
 
   
Although the ridge isn't marked on OS maps as a footpath, it is on access land. There are footpath signs throughout its length and stiles over all walls and fences.

Click for an interactive map





Gate on Dales Way
Mire House
Stopping at the village shop in Dent to buy some pasties for lunch, I walked down to the river Dee, following the Dales Way heading West through numerous fields and gates to Ellers, where I took the footbridge across the river and followed the path up through Mire House, Craggs Farm and Hewthwaite, picking up the Dales Way again.




Before reaching Millthrop, there are good views of Sedbergh, in front of the Howgills.


Sedbergh and the Howgills

Turning East just before Millthrop, I followed a footpath that became increasingly indistinct, taking a bearing East across Frostrow to pick up a bridleway on the far side. This section was quite boggy and hard going. A shorter alternative route (shown in green on the map), would avoid this "off path" section.

Aye Gill Pike

From the end of the bridleway, it is a simple matter of following the wall up to the summit of Aye Gill Pike.



Cowgill Church

From the summit, I followed the wall East to Snaizwold Fell, then followed a ruined wall down to a track which runs past Cowgill Church, and to the Dales Way at Ewegales.






I then  followed the Dales Way all the way back to Dent.

That will teach them!
River Dee
 



Enjoying a well-earned retirement from  show business