Coding, Puzzles and Mathematics

Coders like to solve problems – the high one gets when one finally ‘cracks’ a problem is one that is as powerful as any drug – they are also alpha males – they don’t like to lose… :-) This powerful combination leads to the traditional image of a pale, pasty, overweight  geek in glasses sitting over a computer screen in the wee hours of the night, mumbling to themselves and ingesting caffeine by the pound.

I’m a bit like that (OK – I am not pale and I like to work in the morning but the rest is similar ;-)) except the problem I might be solving may not even have any real world application. It might simply be a solution to a puzzle !!

This post is about coders and their love of puzzles… Most of us have heard and even experienced the classic puzzle question in interviews for development positions. There are numerous books on this topic (the classic “How Would You Move Mount Fuji? Microsoft’s Cult of Puzzle‘ is a great read) – both about the interviewing techniques as well as methods to solve them. I don’t want to get into a discussion about how good or bad the use of this technique is in interviews (I personally don’t favor them – in the wrong hands they can be horrible – like this one ;-) )

What I like to do is examine the puzzles themselves – puzzles can be of several varieties – one can spend hours and hours over them – indeed some people make it a full-time hobby. There are several puzzle competitions  – one of the most challenging being the MIT Puzzle Hunt (the wikipedia entry is very informative). You also have organization leveraging this interest by posting challenges like the FBI

However, the puzzles that interest me are the ones that have a basis in pure logic. I tend to regard puzzles with an eye to the elegance of the solution. A good logical puzzle with an elegantly simple solution is a thing of beauty – I like to go through the reasoning and try and look for extensions or extrapolations. I look at the assumptions and limitations and try to understand the thought process behind the puzzle.

They are a good way to learn, to get ideas on new approaches.  They expand you mind and  are finally but most importantly – they are FUN. I often use them as a fun way to learn new computer languages – good candidates are mathematical puzzles :-)

Here are some nice links – check them out and happy solving :-)

  1. Maths Challenges – Check out the links section where there are some programming challenges.
  2. Project Euler – Awesome site with some really cool puzzles.
  3. Delphi For Fun – The programs are in Delphi which is aversion of Pascal but it has some nice algorithms.
  4. FBI Ciphers – Ciphers are a fun type of puzzle that kind off go off in to crypt-analysis.
  5. Shine’s Take on IT – My friend Shine is reading “How would you move Mount Fuji?” and is blogging about his read.

Mental gymnastics

I have always regarded people who like to think up new dimensions as mental gymnasts. I find it hard enough to wrap my head around space-time, simply conceiving of the existence of other dimensions gives me a headache ;-).

I came across this particular website about a book – Imagining the Tenth Dimension – by Rob Bryanton that changed my mind. The website has a really nice flash animation about how these people conceive of higher dimensions. In the preamble, the author points out that the thoery that he puts forth is not the accepted view of todays physicists. In fact there is a lot of nice discussion about the theory in the forums.

However, if you have a few minutes and you want to limber your brains a bit without stretching it too far, check this out. Who knows, you might actually like it :-)

The Art of Math

I’ve always had a love-hate relationship with mathematics. On the one hand I loved the concept, the premise of mathematics – to describe everything using a set of rules – on the other hand I hated the tedium of it… I loved to learn the concepts and theories, but I hated to sit down and do the sums, especially when there seemed no apparent point to it. That’s one of the reasons why I like programming – it allows one to solve to ‘real’ problems.
Because of this skewed view of math, I love to read about mathematicians and the applications of mathematics even though I suck at it :-)

When I saw this article on Slash-dot today I was immediately intrigued. It deals with one of the more infuriating concepts of math for me – Prime Numbers. A prime number is a number that can be divided only by itself and one. The infuriating part is there is no apparent pattern to prime numbers – you had to memorize them!

According to the article there is a correlation between prime numbers and the energy levels in the nucleus of a large atom. Excerpts from the article:

“Riemann discovered a geometric landscape, the contours of which held
the secret to the way primes are distributed through the universe of
numbers. He realized that he could use something called the zeta
function to build a landscape where the peaks and troughs in a
three-dimensional graph correspond to the outputs of the function. The
zeta function provided a bridge between the primes and the world of
geometry. As Riemann explored the significance of this new landscape,
he realized that the places where the zeta function outputs zero (which
correspond to the troughs, or places where the landscape dips to
sea-level) hold crucial information about the nature of the primes.
Mathematicians call these significant places the zeros.
But then Riemann noticed that it did something even more incredible. As
he marked the locations of the first 10 zeros, a rather amazing pattern
began to emerge. The zeros weren’t scattered all over; they seemed to
be running in a straight line through the landscape. Riemann couldn’t
believe this was just a coincidence. He proposed that all the zeros,
infinitely many of them, would be sitting on this critical line—a
conjecture that has become known as the Riemann Hypothesis.

But what did this amazing pattern mean for the primes? If Riemann’s
discovery was right, it would imply that nature had distributed the
primes as fairly as possible. It would mean that the primes behave
rather like the random molecules of gas in a room: Although you might
not know quite where each molecule is, you can be sure that there won’t
be a vacuum at one corner and a concentration of molecules at the other.

For mathematicians, Riemann’s prediction about the distribution of
primes has been very powerful. But despite nearly 150 years of effort, no one has been able
to confirm that all the zeros really do line up as he predicted.

It seemed the patterns Montgomery was predicting for the way zeros were
distributed on Riemann’s critical line were the same as those predicted
by quantum physicists for energy levels in the nucleus of heavy atoms.
The implications of a connection were immense: If one could understand
the mathematics describing the structure of the atomic nucleus in
quantum physics, maybe the same math could solve the Riemann

Mathematicians were skeptical. Though mathematics has often served
physicists—Einstein, for instance—they wondered whether physics could
really answer hard-core problems in number theory. So in 1996, Peter
Sarnak at Princeton threw down the gauntlet and challenged physicists
to tell the mathematicians something they didn’t know about primes.
Recently, Jon Keating and Nina Snaith, of Bristol, duly obliged.

There is an important sequence of numbers called “the moments of the
Riemann zeta function.” Although we know abstractly how to define it,
mathematicians have had great difficulty explicitly calculating the
numbers in the sequence. We have known since the 1920s that the first
two numbers are 1 and 2, but it wasn’t until a few years ago that
mathematicians conjectured that the third number in the sequence may be
42—a figure greatly significant to those well-versed in The Hitchhiker’s Guide to the Galaxy. It would also prove to be significant in confirming the connection
between primes and quantum physics. Using the connection, Keating and
Snaith not only explained why the answer to life, the universe and the
third moment of the Riemann zeta function should be 42, but also
provided a formula to predict all the numbers in the sequence. Prior to
this breakthrough, the evidence for a connection between quantum
physics and the primes was based solely on interesting statistical