A puzzle that has niggled mathematical minds for years has been solved, researchers say.