1: var best = (from x in Enumerable.Range(0, 17) // horizontal
2: from y in Enumerable.Range(0, 20)
3: let first = data[x, y]
4: let second = data[x + 1, y]
5: let third = data[x + 2, y]
6: let fourth = data[x + 3, y]
7: let answer = first * second *
8: third * fourth
9: select new
10: {
11: X = x,
12: Y = y,
13: Direction = "Right",
14: Values =
15: string.Format("{0}, {1}, {2}, {3}",
16: first, second,
17: third, fourth),
18: Answer = answer
19: }).Concat(from x in Enumerable.Range(0, 20) // Vertical
20: from y in Enumerable.Range(0, 17)
21: let first = data[x, y]
22: let second = data[x, y + 1]
23: let third = data[x, y + 2]
24: let fourth = data[x, y + 3]
25: let answer = first * second *
26: third * fourth
27: select new
28: {
29: X = x,
30: Y = y,
31: Direction = "Down",
32: Values =
33: string.Format("{0}, {1}, {2}, {3}",
34: first, second,
35: third, fourth),
36: Answer = answer
37: }).Concat(from x in Enumerable.Range(0, 17) // Down to the right
38: from y in Enumerable.Range(0, 17)
39: let first = data[x, y]
40: let second = data[x + 1, y + 1]
41: let third = data[x + 2, y + 2]
42: let fourth = data[x + 3, y + 3]
43: let answer = first * second *
44: third * fourth
45: select new
46: {
47: X = x,
48: Y = y,
49: Direction = "DownRight",
50: Values =
51: string.Format("{0}, {1}, {2}, {3}",
52: first, second,
53: third, fourth),
54: Answer = answer
55: }).Concat(from x in Enumerable.Range(3, 17)
56: from y in Enumerable.Range(0, 17)
57: let first = data[x, y]
58: let second = data[x - 1, y + 1]
59: let third = data[x - 2, y + 2]
60: let fourth = data[x - 3, y + 3]
61: let answer = first * second *
62: third * fourth
63: select new
64: {
65: X = x,
66: Y = y,
67: Direction = "DownLeft",
68: Values =
69: string.Format("{0}, {1}, {2}, {3}",
70: first, second,
71: third, fourth),
72: Answer = answer
73: }).OrderByDescending((record) => record.Answer).First();
74:
75: Console.WriteLine(best);