mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Solution to Problem 28
This commit is contained in:
parent
7704151504
commit
81dc221ee2
@ -1,11 +1,12 @@
|
||||
from __future__ import print_function
|
||||
from math import ceil
|
||||
|
||||
def diagonal_sum(n):
|
||||
total = 1
|
||||
|
||||
for i in xrange(n/2):
|
||||
odd = 2*(i+1)+1
|
||||
even = 2*(i+1)
|
||||
for i in xrange(1, int(ceil(n/2.0))):
|
||||
odd = 2*i+1
|
||||
even = 2*i
|
||||
total = total + 4*odd**2 - 6*even
|
||||
|
||||
return total
|
||||
|
Loading…
Reference in New Issue
Block a user