-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem067.cs
52 lines (44 loc) · 1.26 KB
/
Problem067.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Linq;
using System.IO;
namespace Euler
{
class Problem067
{
public int Run()
{
var array = new int[100][];
string[] data = File.ReadAllLines(@"data\p067_triangle.txt");
int lineNum = 0;
foreach (string line in data)
{
array[lineNum] = line.Split(' ').Select(int.Parse).ToArray();
lineNum++;
}
for (int i = 1; i < 100; i++)
{
int length = array[i].Length;
for (int j = 0; j < length; j++)
{
var sumLeft = 0;
if (j - 1 >= 0)
{
sumLeft = array[i - 1][j - 1] + array[i][j];
}
var sumRight = 0;
if (j < i)
{
sumRight = array[i - 1][j] + array[i][j];
}
array[i][j] = Math.Max(sumLeft, sumRight);
}
}
int max = 0;
for (int s = 0; s < array[99].Length; s++)
{
max = Math.Max(max, array[99][s]);
}
return max;
}
}
}