Created
October 29, 2013 10:09
-
-
Save aoisensi/7211950 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.IO; | |
using System.Reflection; | |
using EulerProject; | |
namespace Problem0011 | |
{ | |
class Program | |
{ | |
const int size = 20; | |
const int choice = 4; | |
static void Main(string[] args) | |
{ | |
StreamReader fs = new StreamReader("data.txt", Encoding.Unicode); | |
string str = fs.ReadToEnd(); | |
fs.Close(); | |
var data = str.Split('\n') | |
.Select((l) => l.Split() | |
.Where((s)=>(s.Length > 0)) | |
.Select((n) => (int.Parse(n))) | |
.ToArray()) | |
.ToArray(); | |
var result = new[] { | |
Euler.Range(0, size - choice + 1) | |
.Select((x)=>( | |
Euler.Range(0, size) | |
.Select((y)=>( | |
Euler.Range(choice) | |
.Select((n)=>(new{x=x+n, y=y})))))), | |
Euler.Range(0, size) | |
.Select((x)=>( | |
Euler.Range(0, size - choice + 1) | |
.Select((y)=>( | |
Euler.Range(choice) | |
.Select((n)=>(new{x=x, y=y+n})))))), | |
Euler.Range(0, size - choice + 1) | |
.Select((x)=>( | |
Euler.Range(0, size - choice + 1) | |
.Select((y)=>( | |
Euler.Range(choice) | |
.Select((n)=>(new{x=x+n, y=y+n})))))), | |
Euler.Range(0, size - choice + 1) | |
.Select((x)=>( | |
Euler.Range(0, size - choice + 1) | |
.Select((y)=>( | |
Euler.Range(choice) | |
.Select((n)=>(new{x=x+choice-n-1, y=y+n}))))))} | |
.SelectMany((item)=>(item)) | |
.SelectMany((item)=>(item)) | |
.Select((n)=>( | |
n.Select((a)=>(data[a.y][a.x])) | |
.Aggregate((x,y)=>(x*y)))) | |
.Max(); | |
Console.WriteLine(result); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment