Project Euler problem 28Starting with the number 1 and moving to the right in a clockwise direction a 5 by 5 spiral is formed as follows:$$\begin{array}{rrrrr}\color{red}{21} &22 &23 &24 &\color{red}{25}\\20 & \color{red}{7} & 8 & \color{red}{9} &10\\19 & 6 & \color{red}{1} & 2 &11\\18 & \color{red}{5} & 4 & \color{red}{3} &12\\\color{red}{17} &16 &15 &14 &\color{red}{13}\\\end{array}$$It can be verified that the sum of the numbers on the diagonals is 101.What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?I realized that the spiral was essentially an arithmetic sequence, so I based my code off of that.from timeit import default_timer as timerstart = timer()def spiral_diag_sum(n):    if n < 1: return None    elif n == 1: return 1    elif n % 2 == 0: return None    else:        numbers = [1]        while len(numbers) < (2*n - 1):            increment = int(len(numbers) * 0.5 + 1.5)            for p in range(4):                numbers.append(numbers[-1] + increment)         return sum(numbers)ans = spiral_diag_sum(1001)elapsed_time = (timer() - start) * 1000 # s --> msprint Found %d in %r ms. % (ans, elapsed_time)
Project Euler 28 - Number Spiral Diagonals
python;programming challenge