To solve one of the great mathematical problems of his day, Alan Turing proposed an imaginary programmable calculating machine. But the idea of actually producing a 'thinking machine' did not crystallise until he and his brilliant Bletchley Park colleagues built devices to crack the Nazis' Enigma code, thus ensuring the Allied victory in the Second World War. In so doing, Turing became a champion of artificial intelligence, formulating the famous (and still unbeaten) Turing test that challenges our ideas of human consciousness. But Turing's work was cut short when, as an openly gay man in a time when homosexuality was illegal in Britain, he was apprehended by the authorities and sentenced to a 'treatment' that amounted to chemical castration. Ultimately, it lead to his suicide, and it wasn't until 2013, after many years of campaigning, that he received a posthumous royal pardon. With a novelist's sensitivity, David Leavitt portrays Turing in all his humanity - his eccentricities, his brilliance, his fatal candour - while elegantly explaining his work and its implications.