Solution to n queens problem