Wednesday 30 January 2013

Another slip of the tongue

A cracker from a continuity announcer this afternoon:

"At 2:15, Patrick Malahide stars as Albert Speer, or prisoner number five as he was known throughout his twenty years in Spandau Ballet"

I think Speer played the saxaphone.

Sunday 27 January 2013

Enigma 49

New Scientist magazine's Enigma #49 problem can be solved with a bit of number theory. Generalising the problem to finding a number whose square has the same last N digits as itself:

z= z mod 10N  →  z(z-1) = 0 mod 10N. One factor of z(z-1) is odd, the other even. The even factor is a multiple of 2N.

For a solution other than 0 or 1, the odd factor of z(z-1) must be a multiple of 5N (if the even factor is a multiple of 5 it is a multiple of 10, so the odd factor is congruent to 1 or 9 mod 10 and therefore not a multiple of 5, so the even factor is a multiple of 10N).

So the solution is one of
a)  z=2Nx,    z-1=5Ny
b) z-1=2Nx,   z=5Ny

Solutions to the Diophantine equation 2Nx+ 5Ny=1  produce the solutions
a) z=2N(x mod 5N)
b) z=5N(y mod 2N)

So, some Python code. Function egcd is a standard recursive implementation of the Extended Euclidean Algorithm to find solutions to a linear Diophantine equation (and the gcd as a by-product).

def egcd(a,b):
  if b == 0:
    return [1,0,a]
  else:
    x,y,g = egcd(b, a%b)
    return [y, x - (a//b)*y, g] 

for N in range(1,40):

  x,y,g = egcd(5**N, 2**N)
  print "N =",N, sorted([(x%2**N)*5**N, (y%5**N)*2**N])

Friday 4 January 2013

A slip of the tongue

This had me laughing for several minutes.

"Squawk"
Matt Ridley talking on "The Value of Culture" on Radio 4 this morning (about 6 mins 30 sec in from the start):

"I live in a culture called science which is a tribe, but that tribe has no particular place in the world, but yet it is just as narrow as if it were a particular New Guinea group of people who killed birds of paradise with blowtorches"