Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 12 lines (10 sloc) 0.708 kb
5dcac67 @akshar-raaj Problem 28 solved, sum of diagonals in a 1001 by 1001 spiral
authored
1 init_sum =1
16f268a @akshar-raaj comments added to euler28
authored
2 current_spiral_numbers_diff = 2 #For the 3 by 3 spiral, difference between diagonal elements is 3
5dcac67 @akshar-raaj Problem 28 solved, sum of diagonals in a 1001 by 1001 spiral
authored
3 current_number = 3
16f268a @akshar-raaj comments added to euler28
authored
4 for i in range(3,1003,2): #Next to 3 by 3 spiral, its 5 by 5 spiral followed by 7 by 7 and so on till 1001 by 1001
5 for j in range(1,5): #Four elements in each spiral needs to be considered except "1" which is alreadey taken into account in init_sum
5dcac67 @akshar-raaj Problem 28 solved, sum of diagonals in a 1001 by 1001 spiral
authored
6 init_sum += current_number
7 current_number += current_spiral_numbers_diff
16f268a @akshar-raaj comments added to euler28
authored
8 current_spiral_numbers_diff += 2 #For each spiral, difference between diagonal keeps increasing by 2, i.e for 3 by 3 spiral its 2, for 5 by 5 spiral its 4 and so on.
5dcac67 @akshar-raaj Problem 28 solved, sum of diagonals in a 1001 by 1001 spiral
authored
9 current_number = current_number+2
10 print init_sum
11
12
Something went wrong with that request. Please try again.