License Public Domain
Lines 19
Keywords
Euler28 (8)
Permissions
Owner: neary
Group Owner: SnortSnort
Viewable by Everyone
Editable by neary and "SnortSnort" Group Members

Euler Prolem 28 Atom Feed 0

# 's
 1#include <iostream>
2using namespace std;
3
4int main()
5{
6 int num = 1;
7 int sum = 1;
8 const int dimensions = 1001;
9 for (int skip = 1; skip <= dimensions-2; skip++)
10 {
11 for (int j = 1; j <= 4; j++)
12 {
13 num += 1+skip;
14 sum += num;
15 }
16 skip++;
17 }
18 cout << sum << endl;
19 return 0;
20}

Comments

over 3 years ago (15 Feb 2013 at 04:45 PM) by msgordon
Kyle, you beat me to it. I thought about 'building the spiral' as you did, but I went a different way. I noticed that it's possible to calculate the corners analytically, and then just add them up for each square size. I posted this solution as a comment in my code.